当前位置: 首页>>代码示例>>Python>>正文


Python QtWidgets.QStyleOptionViewItem方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QStyleOptionViewItem方法的典型用法代码示例。如果您正苦于以下问题:Python QtWidgets.QStyleOptionViewItem方法的具体用法?Python QtWidgets.QStyleOptionViewItem怎么用?Python QtWidgets.QStyleOptionViewItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets的用法示例。


在下文中一共展示了QtWidgets.QStyleOptionViewItem方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: paint

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def paint(self, painter, option, index):
            options = QtWidgets.QStyleOptionViewItem(option)
            self.initStyleOption(options, index)

            style = QtGui.QApplication.style() if options.widget is None\
                else options.widget.style()

            doc = QtGui.QTextDocument()
            doc.setHtml(options.text)

            options.text = ""
            style.drawControl(QtGui.QStyle.CE_ItemViewItem, options, painter)

            ctx = QtGui.QAbstractTextDocumentLayout.PaintContext()

            textRect = style.subElementRect(
                QtGui.QStyle.SE_ItemViewItemText, options, options.widget)
            painter.save()
            painter.translate(textRect.topLeft())
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
            doc.documentLayout().draw(painter, ctx)

            painter.restore() 
开发者ID:pyrocko,项目名称:kite,代码行数:25,代码来源:sources_dock.py

示例2: paint

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex):
        if self.colors:
            try:
                item = index.model().data(index)
                index = self.items.index(item) if item in self.items else int(item)
                color = self.colors[index]

                x, y, h = option.rect.x(), option.rect.y(), option.rect.height()

                rect = QRectF(x + 8, y + h / 2 - 8, 16, 16)
                painter.fillRect(rect, QColor("black"))
                rect = rect.adjusted(1, 1, -1, -1)
                painter.fillRect(rect, QColor(color.red(), color.green(), color.blue(), 255))
            except:
                super().paint(painter, option, index)
        else:
            super().paint(painter, option, index) 
开发者ID:jopohl,项目名称:urh,代码行数:19,代码来源:ComboBoxDelegate.py

示例3: paint

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def paint(self, painter, option, index):
            painter.save()

            options = Qw.QStyleOptionViewItem(option)

            self.initStyleOption(options, index)
            self.doc.setHtml(options.text)
            options.text = ''

            style = (Qw.QApplication.style() if options.widget is None
                else options.widget.style())
            style.drawControl(Qw.QStyle.CE_ItemViewItem, options, painter)

            ctx = Qg.QAbstractTextDocumentLayout.PaintContext()

            if option.state & Qw.QStyle.State_Selected:
                ctx.palette.setColor(Qg.QPalette.Text,
                                     option.palette.color(
                                         Qg.QPalette.Active,
                                         Qg.QPalette.HighlightedText))
            else:
                ctx.palette.setColor(Qg.QPalette.Text,
                                     option.palette.color(
                                         Qg.QPalette.Active, Qg.QPalette.Text))

            textRect = style.subElementRect(Qw.QStyle.SE_ItemViewItemText,
                                            options, None)

            if index.column() != 0:
                textRect.adjust(5, 0, 0, 0)

            thefuckyourshitup_constant = 4
            margin = (option.rect.height() - options.fontMetrics.height()) // 2
            margin = margin - thefuckyourshitup_constant
            textRect.setTop(textRect.top() + margin)

            painter.translate(textRect.topLeft())
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
            self.doc.documentLayout().draw(painter, ctx)

            painter.restore() 
开发者ID:DoTheEvo,项目名称:ANGRYsearch,代码行数:43,代码来源:angrysearch.py

示例4: sizeHint

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def sizeHint(self, option, index):
            options = QtWidgets.QStyleOptionViewItem(option)
            self.initStyleOption(options, index)

            doc = QtGui.QTextDocument()
            doc.setHtml(options.text)
            doc.setTextWidth(options.rect.width())

            return QtCore.QSize(doc.idealWidth(), doc.size().height()) 
开发者ID:pyrocko,项目名称:kite,代码行数:11,代码来源:sources_dock.py

示例5: paint

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def paint(self, painter, option, index):
        view_option = QStyleOptionViewItem(option)
        view_option.decorationAlignment |= Qt.AlignHCenter
        # Even though we told Qt that we don't want any selection on our
        # list, it still adds a blue rectangle on focused items.
        # So we just get rid of focus.
        if option.state & QStyle.State_HasFocus:
            view_option.state &= ~QStyle.State_HasFocus
        super().paint(painter, view_option, index) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:11,代码来源:notification_center_widget.py

示例6: paintEvent

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def paintEvent(self, event: QPaintEvent):

        if self.isVisible():

            block: QTextBlock = self.editor.firstVisibleBlock()
            height: int = self.fontMetrics().height()
            number: int = block.blockNumber()

            painter = QPainter(self)
            painter.fillRect(event.rect(), QColor(53, 53, 53))
            font = painter.font()
            font.setPointSize(15)

            for blocks in self.editor.currentlyVisibleBlocks:

                bl: QTextBlock = blocks[-1]
                blockGeometry: QRectF = self.editor.blockBoundingGeometry(bl)
                offset: QPointF = self.editor.contentOffset()
                blockTop: int = int(blockGeometry.translated(offset).top() + 1)
                pattern = re.compile(
                    "\\s*(def|class|with|if|else|elif|for|while|async).*:")
                if pattern.match(bl.text()):

                    options = QStyleOptionViewItem()
                    options.rect = QRect(0, blockTop, self.width(), height)
                    options.state = (QStyle.State_Active |
                                     QStyle.State_Item |
                                     QStyle.State_Children)

                    if bl.userState() == UNFOLDED_STATE:
                        options.state |= QStyle.State_Open

                    self.style().drawPrimitive(QStyle.PE_IndicatorBranch, options,
                                               painter, self)
            painter.end() 
开发者ID:CountryTk,项目名称:Hydra,代码行数:37,代码来源:foldArea.py

示例7: createEditor

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QtCore.QModelIndex) -> QWidget:
        editor = QSpinBox(parent)
        editor.setFrame(False)
        editor.setMinimum(0)
        editor.setMaximum(100)
        return editor 
开发者ID:haruiz,项目名称:CvStudio,代码行数:8,代码来源:treeview_model.py

示例8: createEditor

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
        editor = QCheckBox(parent)
        editor.stateChanged.connect(self.stateChanged)
        return editor 
开发者ID:jopohl,项目名称:urh,代码行数:6,代码来源:CheckBoxDelegate.py

示例9: createEditor

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
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 
开发者ID:jopohl,项目名称:urh,代码行数:32,代码来源:ComboBoxDelegate.py

示例10: updateEditorGeometry

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def updateEditorGeometry(self, editor: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
        editor.setGeometry(option.rect) 
开发者ID:jopohl,项目名称:urh,代码行数:4,代码来源:ComboBoxDelegate.py

示例11: createEditor

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
        editor = self._get_editor(parent)
        editor.setMinimum(self.minimum)
        editor.setMaximum(self.maximum)
        editor.setSuffix(self.suffix)
        editor.valueChanged.connect(self.valueChanged)
        return editor 
开发者ID:jopohl,项目名称:urh,代码行数:9,代码来源:SpinBoxDelegate.py

示例12: createEditor

# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyleOptionViewItem [as 别名]
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex):
        editor = SectionComboBox(parent)
        editor.setItemDelegate(SectionItemDelegate(editor.itemDelegate().parent()))
        if sys.platform == "win32":
            # Ensure text entries are visible with windows combo boxes
            editor.setMinimumHeight(self.sizeHint(option, index).height() + 10)

        for title, items in self.items.items():
            editor.add_parent_item(title)
            for item in items:
                editor.add_child_item(item)
        editor.currentIndexChanged.connect(self.current_index_changed)
        return editor 
开发者ID:jopohl,项目名称:urh,代码行数:15,代码来源:SectionComboBoxDelegate.py


注:本文中的PyQt5.QtWidgets.QStyleOptionViewItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。