Python PyQt5.QtCore.Qt 模块,DecorationRole() 实例源码

我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用PyQt5.QtCore.Qt.DecorationRole()

项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex) -> None:
        r = option.rect
        pencolor = Qt.white if self.theme == 'dark' else Qt.black
        if self.parent.isEnabled():
            if option.state & QStyle.State_Selected:
                painter.setBrush(QColor(150, 190, 78, 150))
            elif option.state & QStyle.State_MouseOver:
                painter.setBrush(QColor(227, 212, 232))
                pencolor = Qt.black
            else:
                brushcolor = QColor(79, 85, 87, 175) if self.theme == 'dark' else QColor('#EFF0F1')
                painter.setBrush(Qt.transparent if index.row() % 2 == 0 else brushcolor)
        painter.setPen(Qt.NoPen)
        painter.drawRect(r)
        thumb = QIcon(index.data(Qt.DecorationRole + 1))
        starttime = index.data(Qt.DisplayRole + 1)
        endtime = index.data(Qt.UserRole + 1)
        externalPath = index.data(Qt.UserRole + 2)
        r = option.rect.adjusted(5, 0, 0, 0)
        thumb.paint(painter, r, Qt.AlignVCenter | Qt.AlignLeft)
        painter.setPen(QPen(pencolor, 1, Qt.SolidLine))
        r = option.rect.adjusted(110, 8, 0, 0)
        painter.setFont(QFont('Noto Sans UI', 10 if sys.platform == 'darwin' else 8, QFont.Bold))
        painter.drawText(r, Qt.AlignLeft, 'FILENAME' if len(externalPath) else 'START')
        r = option.rect.adjusted(110, 20, 0, 0)
        painter.setFont(QFont('Noto Sans UI', 11 if sys.platform == 'darwin' else 9, QFont.Normal))
        if len(externalPath):
            painter.drawText(r, Qt.AlignLeft, self.clipText(os.path.basename(externalPath), painter))
        else:
            painter.drawText(r, Qt.AlignLeft, starttime)
        if len(endtime) > 0:
            r = option.rect.adjusted(110, 45, 0, 0)
            painter.setFont(QFont('Noto Sans UI', 10 if sys.platform == 'darwin' else 8, QFont.Bold))
            painter.drawText(r, Qt.AlignLeft, 'RUNTIME' if len(externalPath) else 'END')
            r = option.rect.adjusted(110, 60, 0, 0)
            painter.setFont(QFont('Noto Sans UI', 11 if sys.platform == 'darwin' else 9, QFont.Normal))
            painter.drawText(r, Qt.AlignLeft, endtime)
        if self.parent.verticalScrollBar().isVisible():
            self.parent.setFixedWidth(210)
        else:
            self.parent.setFixedWidth(190)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def getColor(self):
        color = self.itemData(self.currentIndex(), Qt.DecorationRole)
        return color
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def setColor(self, color):
        self.setCurrentIndex(self.findData(color, Qt.DecorationRole))
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def populateList(self):
        for i, colorName in enumerate(QColor.colorNames()):
            color = QColor(colorName)
            self.insertItem(i, colorName)
            self.setItemData(i, color, Qt.DecorationRole)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def getColor(self):
        color = self.itemData(self.currentIndex(), Qt.DecorationRole)
        return color
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def setColor(self, color):
        self.setCurrentIndex(self.findData(color, Qt.DecorationRole))
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def populateList(self):
        for i, colorName in enumerate(QColor.colorNames()):
            color = QColor(colorName)
            self.insertItem(i, colorName)
            self.setItemData(i, color, Qt.DecorationRole)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        data = self.itemData(QModelIndex)
        if role == Qt.DisplayRole:
            if QModelIndex.column() == 1:  # ??? ??? ????? ?? ?? ??.
                return QVariant()
            return data[0]
        if role == Qt.DecorationRole:
            return QPixmap(data[0]).scaledToHeight(25)
        return QVariant()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def __init__(self, data=None, parent=None):
        QStandardItemModel.__init__(self, parent)
        for i, d in enumerate(data):
            item = QStandardItem(d["name"])
            item.setData(d["image"], Qt.DecorationRole)
            self.setItem(i, 0, item)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        data = self.itemData(QModelIndex)
        if role == Qt.DisplayRole:
            return "%s" % (data[role])
        elif role in data and role == Qt.DecorationRole:
            return QPixmap(data[role]).scaledToHeight(25)
        elif role == Qt.UserRole:
            print(data[role])
        return QVariant()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        item = self._data[QModelIndex.row()]

        if role == Qt.DisplayRole:
            return "%s" % (item['name'])
        elif role == Qt.DecorationRole:
            return QColor(item['color'])
        elif role == Qt.BackgroundRole:
            return QBrush(Qt.Dense7Pattern)
        elif role == Qt.ToolTipRole:
            return "Tool Tip: %s" % (item['name'])
        return QVariant()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def __init__(self, data):
        """
        :param data = [{"type":str, "objects":[str, ...]}, "picture":str, ...]
        """
        QStandardItemModel.__init__(self)
        self._data = data

        # QStandardItem? ???? ?? model? ??
        for j, d in enumerate(data):
            item = QStandardItem(d["type"])
            for obj in d["objects"]:
                child = QStandardItem(obj)
                child.setData(d["picture"], Qt.DecorationRole)
                item.appendRow(child)
            self.setItem(j, 0, item)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def slot_show_picture(self, QModelIndex):
        data = self.model.itemData(QModelIndex)
        if Qt.DecorationRole not in data:
            # DecoreationRole ?? ???? ??? ??? ? ? ??? ????
            return
        self.lb.setPixmap(QPixmap(data[Qt.DecorationRole]))
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def __init__(self, data):
        QStandardItemModel.__init__(self)
        self._data = data
        for j, d in enumerate(data):
            item = QStandardItem(d["type"])
            for obj in d["objects"]:
                child = QStandardItem(obj)
                child.setData(d["picture"], Qt.DecorationRole)  # Role ??? ? ?? ??? ? ??? ??
                item.appendRow(child)
            self.setItem(j, 0, item)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def data(self, QModelIndex, role=None):
        # itemData? ????? ?? QModelIndex? ???? ????? ??? ?? ????.
        data = self.itemData(QModelIndex)

        if role == Qt.DisplayRole:
            ret = data[role]
        elif role in data and role == Qt.DecorationRole:
            ret = QPixmap(data[role]).scaledToHeight(25)
        else:
            ret = QVariant()
        return ret
项目:DownloaderForReddit    作者:MalloyDelacroix    | 项目源码 | 文件源码
def data(self, index, role=Qt.DisplayRole):
        if role == Qt.DisplayRole:
            return self.display_list[index.row()]
        elif role == Qt.DecorationRole:
            return None
        elif role == Qt.ToolTipRole:
            return None
        elif role == Qt.EditRole:
            return self.display_list[index.row()]
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def data(self, index: QModelIndex, role=None):
        item = self.getItem(index)
        if role == Qt.DisplayRole:
            return item.data()
        elif role == Qt.DecorationRole and item.is_group:
            return QIcon.fromTheme("folder")
        elif role == Qt.CheckStateRole:
            return item.show
        elif role == Qt.FontRole:
            if item.is_group and self.rootItem.index_of(item) in self.controller.active_group_ids:
                font = QFont()
                font.setBold(True)
                return font
            elif item.protocol in self.controller.selected_protocols:
                font = QFont()
                font.setBold(True)
                return font
        elif role == Qt.ToolTipRole:
            return item.data()
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def data(self, index: QModelIndex, role=None):
        item = self.getItem(index)
        if role == Qt.DisplayRole:#
            return item.data()
        elif role == Qt.DecorationRole and item.is_group:
            return QIcon.fromTheme("folder")
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
        editor = QComboBox(parent)
        if sys.platform == "win32":
            # Ensure text entries are visible with windows combo boxes
            editor.setMinimumHeight(self.sizeHint(option, index).height() + 10)

        editor.addItems(self.items)

        if self.is_editable:
            editor.setEditable(True)
            editor.setInsertPolicy(QComboBox.NoInsert)

        if self.current_edit_text:
            editor.setEditText(self.current_edit_text)

        if self.colors:
            img = QImage(16, 16, QImage.Format_RGB32)
            painter = QPainter(img)

            painter.fillRect(img.rect(), Qt.black)
            rect = img.rect().adjusted(1, 1, -1, -1)
            for i, item in enumerate(self.items):
                color = self.colors[i]
                painter.fillRect(rect, QColor(color.red(), color.green(), color.blue(), 255))
                editor.setItemData(i, QPixmap.fromImage(img), Qt.DecorationRole)

            del painter
        editor.currentIndexChanged.connect(self.currentIndexChanged)
        editor.editTextChanged.connect(self.on_edit_text_changed)
        return editor
项目:FIRST-plugin-ida    作者:vrtadmin    | 项目源码 | 文件源码
def data(self, index, role=Qt.DisplayRole):
                '''The data stored under the given role for the item referred
                to by the index.

                Args:
                    index (:obj:`QtCore.QModelIndex`): Index
                    role (:obj:`Qt.ItemDataRole`): Default :obj:`Qt.DisplayRole`

                Returns:
                    data
                '''
                if role == Qt.DisplayRole:
                    row = self._data[index.row()]
                    if (index.column() == 0) and (type(row) != dict):
                        return row

                    elif index.column() < self.columnCount():
                        if type(row) == dict:
                            if self.header[index.column()] in row:
                                return row[self.header[index.column()]]
                            elif self.header[index.column()].lower() in row:
                                return row[self.header[index.column()].lower()]

                        return row[index.column()]

                    return None

                elif role == Qt.FontRole:
                    return QtGui.QFont().setPointSize(30)

                elif role == Qt.DecorationRole and index.column() == 0:
                    return None

                elif role == Qt.TextAlignmentRole:
                    return Qt.AlignLeft;
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def getColor(self):
        color = self.itemData(self.currentIndex(), Qt.DecorationRole)
        return color
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def setColor(self, color):
        self.setCurrentIndex(self.findData(color, Qt.DecorationRole))
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def populateList(self):
        for i, colorName in enumerate(QColor.colorNames()):
            color = QColor(colorName)
            self.insertItem(i, colorName)
            self.setItemData(i, color, Qt.DecorationRole)
项目:FIRST-plugin-ida    作者:vrtadmin    | 项目源码 | 文件源码
def data(self, index, role):
                if not index.isValid():
                    return None

                if not (0 <= index.row() < self.rowCount()):
                    return None

                elif role == Qt.FontRole:
                    return QtGui.QFont().setPointSize(30)

                elif role == Qt.DecorationRole and index.column() == 0:
                    return None

                elif role == Qt.TextAlignmentRole:
                    return Qt.AlignLeft;

                #   Color background
                if role == Qt.BackgroundRole:
                    function = self._data[index.row()]

                    #   Row is selected
                    if index.row() in self.rows_selected:
                        return FIRST.color_selected

                    #   Data has been updated since original
                    if function.has_changed:
                        return FIRST.color_changed

                    #
                    if function.id is not None:
                        return FIRST.color_unchanged

                    #   Return the default color
                    return FIRST.color_default

                if role == Qt.DisplayRole:
                    function = self._data[index.row()]

                    column = index.column()
                    if 0 == column:
                        return '0x{0:X}'.format(function.address)

                    elif 1 == column:
                        return function.name

                    elif 2 == column:
                        return function.prototype

                    elif 3 == column:
                        return function.comment

                    return None

                return super(FIRST.Model.Upload, self).data(index, role)