Ejemplo n.º 1
0
    def data(self, index, role=Qt.DisplayRole):
        row = index.row()
        column = index.column()
        cell_data = self.grid_data[row][column]
        is_word_cell = cell_data[0]
        clue_index = cell_data[1] or cell_data[2]

        if role == Qt.DisplayRole:
            return self.solution_data[row][column]
        if role == Qt.EditRole:
            return self.solution_data[row][column]
        elif role == Qt.BackgroundRole:
            if is_word_cell:
                if clue_index:
                    icon_path = os.path.join(icons_folder,
                                             '{}.svg'.format(clue_index))
                    brush = QBrush()
                    pixmap = QPixmap(icon_path)
                    brush.setTexture(pixmap)
                    return brush
                else:
                    return QColor(Qt.white)
            else:
                return QColor(Qt.black)
        elif role == Qt.FontRole:
            font = QFont(font_name, font_size)
            return font
        elif role == Qt.TextAlignmentRole:
            return Qt.AlignCenter
        return None
Ejemplo n.º 2
0
    def data(self, index, role=Qt.DisplayRole):
        row = index.row()
        column = index.column()
        cell_data = self.grid_data[row][column]
        is_word_cell = cell_data[0]
        clue_index = cell_data[1] or cell_data[2]

        if role == Qt.DisplayRole:
            return self.solution_data[row][column]
        if role == Qt.EditRole:
            return self.solution_data[row][column]
        #elif role == Qt.DecorationRole:
        #  if clue_index:
        #    icon_path = os.path.join(icons_folder, '{}.svg'.format(clue_index))
        #    return QIcon(icon_path)
        #  else:
        #    return None
        elif role == Qt.BackgroundRole:
            if is_word_cell:
                if clue_index:
                    icon_path = os.path.join(icons_folder,
                                             '{}.svg'.format(clue_index))
                    renderer = QSvgRenderer(icon_path)
                    pixmap = QPixmap(QSize(grid_cell_size, grid_cell_size))
                    pixmap.fill(Qt.transparent)
                    painter = QPainter()
                    renderer.render(painter, pixmap.rect())
                    brush = QBrush()
                    brush.setTexture(pixmap)
                    return brush
                else:
                    return QColor(Qt.white)
            else:
                return QColor(Qt.black)
        elif role == Qt.FontRole:
            font = QFont(font_name, font_size)
            return font
        elif role == Qt.TextAlignmentRole:
            return Qt.AlignCenter
        return None