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


Python QtWidgets.QStyledItemDelegate类代码示例

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


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

示例1: __init__

    def __init__(self, parent=None):
        if isinstance(parent, QWidget):
            self._font = parent.font()
        else:
            self._font = None

        QStyledItemDelegate.__init__(self, parent)
开发者ID:hlamer,项目名称:enki,代码行数:7,代码来源:htmldelegate.py

示例2: setEditorData

 def setEditorData(self, editor, index):
     text = index.model().data(index, Qt.DisplayRole)
     if index.column() == residNum:
         if text is None:
             value = 0
         elif isinstance(text, int):
             value = text
         else:
             value = int(re.sub(r"[., ]", "", text))
         editor.setValue(value)
         # elif index.column() == residName:
         # editor.setText(text)
     elif index.column() == atomName:
         editor.setText(text)
     elif index.column() == atomNum:
         if text is None:
             value = 0
         elif isinstance(text, int):
             value = text
         else:
             value = int(re.sub(r"[., ]", "", text))
         editor.setValue(value)
     elif index.column() in (X, Y, Z):
         if text is None:
             value = 0
         elif isinstance(text, int):
             value = text
         else:
             value = float(text)
         editor.setValue(value)
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
开发者ID:hovo1990,项目名称:GROM,代码行数:32,代码来源:gro_model.py

示例3: setEditorData

 def setEditorData(self, editor, index):
     text = index.model().data(index, Qt.DisplayRole)
     if index.column() == name:
         editor.setText(text)
         # elif index.column() == resName:
         # editor.setItemText(text)
     elif index.column() == ChainID:
         editor.setText(text)
     elif index.column() == resNum:
         if text is None:
             value = 0
         elif isinstance(text, int):
             value = text
         else:
             value = int(re.sub(r"[., ]", "", text))
         editor.setValue(value)
     elif index.column() in (serial, X, Y, Z, occupancy, charge):
         if text is None:
             value = 0
         elif isinstance(text, int):
             value = text
         else:
             try:
                 value = float(text)
             except:
                 value = 0
         editor.setValue(value)
     elif index.column() == element:
         editor.setText(text)
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
开发者ID:hovo1990,项目名称:GROM,代码行数:31,代码来源:pdb_model_0_88.py

示例4: paint

    def paint(self, painter, option, index):
        """Performs custom painting of value of data in the model and decorations.

         Performs custom painting of value of data in the model at the specified index
         plus any decorations used in that column.

         Args:
            painter - QPainter
            option - QStyleOptionViewItem
            index - QModelIndex
        """
        xOffset = 0
        # First added for #15, the painting of custom amount information.  This can
        # be used as a pattern for painting any column of information.
        value_painter = self._get_value_painter(index)
        self._display_text = value_painter is None
        QStyledItemDelegate.paint(self, painter, option, index)
        if value_painter is not None:
            value_option = QStyleOptionViewItem(option)
            rect = value_option.rect
            rect = QRect(rect.left(), rect.top(), rect.width() - xOffset, rect.height())
            value_option.rect = rect
            value_painter.paint(painter, value_option, index)

        decorations = self._get_decorations(index, bool(option.state & QStyle.State_Selected))
        for dec in decorations:
            pixmap = dec.pixmap
            x = option.rect.right() - pixmap.width() - xOffset
            y = option.rect.center().y() - (pixmap.height() // 2)
            rect = QRect(x, y, pixmap.width(), pixmap.height())
            painter.drawPixmap(rect, pixmap)
            xOffset += pixmap.width()
开发者ID:patrickatamaniuk,项目名称:moneyguru,代码行数:32,代码来源:item_delegate.py

示例5: __init__

 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
     self.factor = settings.corkSizeFactor / 100.
     self.defaultSize = QSize(300, 200)
     self.lastPos = None
     self.editing = None
     self.margin = 5
开发者ID:georgehank,项目名称:manuskript,代码行数:7,代码来源:corkDelegate.py

示例6: __init__

    def __init__(self, parent=None):
        QStyledItemDelegate.__init__(self, parent)
        self.factor = settings.corkSizeFactor / 100.
        self.lastPos = None
        self.editing = None
        self.margin = 5

        self.bgColors = {}
开发者ID:olivierkes,项目名称:manuskript,代码行数:8,代码来源:corkDelegate.py

示例7: setEditorData

 def setEditorData(self, editor, idx):
     #print(editor.metaObject().className() )
     name = idx.sibling(idx.row(), 0).data()
     if self.editors[name][0] == self.TEXT_DELEGATE:
         QStyledItemDelegate.setEditorData(self, editor, idx)
     else:
         value = idx.model().data(idx, Qt.EditRole)
         editor.set_index(value)
开发者ID:harryzhurov,项目名称:kicad-tools,代码行数:8,代码来源:inspector.py

示例8: redo

 def redo(self):
     if self.first_time == True:
         QStyledItemDelegate.setModelData(self.parent, self.editor, self.model,
                                          self.index)  # this is very important this is the one that changes the text
         self.redo_value = self.index.model().data(self.index, Qt.DisplayRole)
         self.first_time = False
     elif self.first_time == False:
         self.model.setData(self.index, self.redo_value)
     self.model.dataChanged.emit(self.index, self.index)
开发者ID:hovo1990,项目名称:GROM,代码行数:9,代码来源:undoCommands.py

示例9: initStyleOption

 def initStyleOption(self, option, index):
     QStyledItemDelegate.initStyleOption(self, option, index)
     decorations = self._get_decorations(index, bool(option.state & QStyle.State_Selected))
     if decorations:
         option.decorationPosition = QStyleOptionViewItem.Right
         decorationWidth = sum(dec.pixmap.width() for dec in decorations)
         decorationHeight = max(dec.pixmap.height() for dec in decorations)
         option.decorationSize = QSize(decorationWidth, decorationHeight)
         option.features |= QStyleOptionViewItem.HasDecoration
开发者ID:patrickatamaniuk,项目名称:moneyguru,代码行数:9,代码来源:item_delegate.py

示例10: paint

    def paint(self, painter, option, index):
        QStyledItemDelegate.paint(self, painter, option, index)

        if index.isValid() and index.internalPointer().data(Outline.status.value) not in ["", None, "0", 0]:
            opt = QStyleOptionComboBox()
            opt.rect = option.rect
            r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxArrow)
            option.rect = r
            qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
开发者ID:TenKeyAngle,项目名称:manuskript,代码行数:9,代码来源:outlineDelegates.py

示例11: paint

    def paint(self, painter: QPainter,
                    option: QStyleOptionViewItem,
                    model_index: QModelIndex):
        column = model_index.column()
        new_rect = QRect(option.rect)
        if column == NAME_COL:  # Part Name
            option.displayAlignment = Qt.AlignVCenter
            QStyledItemDelegate.paint(self, painter, option, model_index)
        if column == LOCKED_COL:  # Visibility
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionButton()
            styleoption.rect = new_rect
            checked = model_index.model().data(model_index, Qt.EditRole)
            styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
            # make the check box look a little more active by changing the pallete
            styleoption.palette.setBrush(QPalette.Button, Qt.white)
            styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black)
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
            if checked:
                # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark
                # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
                # _QCOMMONSTYLE.drawItemText(painter, new_rect, Qt.AlignCenter, styleoption.palette, True, 'L')
                icon = QPixmap(":/outlinericons/lock")
                _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter, icon)
        if column == VISIBLE_COL:  # Visibility
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionButton()
            styleoption.rect = new_rect
            checked = model_index.model().data(model_index, Qt.EditRole)
            styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
            # make the check box look a little more active by changing the pallete
            styleoption.palette.setBrush(QPalette.Button, Qt.white)
            styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black)
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
            if checked:
                # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark
                # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
                icon = QPixmap(":/outlinericons/eye")
                _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter, icon)
        elif column == COLOR_COL:  # Color

            # Alternate way to get color
            # outline_tw = self.parent()
            # item = outline_tw.itemFromIndex(model_index)
            # color = item.getColor()
            # print("COLOR_COL", item)

            color = model_index.model().data(model_index, Qt.EditRole)
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionViewItem()
            brush = getBrushObj(color)
            styleoption.palette.setBrush(QPalette.Button, brush)
            styleoption.rect = new_rect
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
        else:
            QStyledItemDelegate.paint(self, painter, option, model_index)
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:56,代码来源:outlinertreewidget.py

示例12: setModelData

        def setModelData(self, editor, model, idx):
            name = idx.sibling(idx.row(), 0).data()
            if self.editors[name][0] == self.TEXT_DELEGATE:
                QStyledItemDelegate.setModelData(self, editor, model, idx)
            else:
                value = editor.currentText()
                values = self.editors[name][1]
                if value not in values:
                    values.append(value)

                QStyledItemDelegate.setModelData(self, editor, model, idx)
开发者ID:harryzhurov,项目名称:kicad-tools,代码行数:11,代码来源:inspector.py

示例13: setEditorData

 def setEditorData(self, editor: QWidget, model_index: QModelIndex):
     column = model_index.column()
     if column == NAME_COL:  # Part Name
         text_QString = model_index.model().data(model_index, Qt.EditRole)
         editor.setText(text_QString)
     # elif column == VISIBLE_COL: # Visibility
     #     value = model_index.model().data(model_index, Qt.EditRole)
     #     editor.setChecked(value)
     elif column == COLOR_COL:  # Color
         value = model_index.model().data(model_index, Qt.EditRole)
         editor.setCurrentColor(QColor(value))
     else:
         QStyledItemDelegate.setEditorData(self, editor, model_index)
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:13,代码来源:outlinertreewidget.py

示例14: __init__

    def __init__(self, layersView, listModel, parent=None):
        QStyledItemDelegate.__init__(self, parent=parent)
        self.currentIndex = -1
        self._view = layersView
        self._w = LayerItemWidget()
        self._listModel = listModel
        self._listModel.rowsAboutToBeRemoved.connect(self.handleRemovedRows)

        # We keep a dict of all open editors for easy access.
        # Note that the LayerWidget uses persistent editors.
        # (This is for convenience of testing.)
        # This is also why we don't need to override the paint() method here.
        self._editors = {}
开发者ID:ilastik,项目名称:volumina,代码行数:13,代码来源:layerwidget.py

示例15: updateEditorGeometry

 def updateEditorGeometry(self, editor: QWidget,
                                 option: QStyleOptionViewItem,
                                 model_index: QModelIndex):
     column = model_index.column()
     if column == NAME_COL:
         editor.setGeometry(option.rect)
     # elif column == VISIBLE_COL:
     #     rect = QRect(option.rect)
     #     delta = option.rect.width() / 2 - 9
     #     rect.setX(option.rect.x() + delta) # Hack to center the checkbox
     #     editor.setGeometry(rect)
     # elif column == COLOR_COL:
     #     editor.setGeometry(option.rect)
     else:
         QStyledItemDelegate.updateEditorGeometry(self, editor, option, model_index)
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:15,代码来源:outlinertreewidget.py


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