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


Python QModelIndex.model方法代码示例

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


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

示例1: paint

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
    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,代码行数:58,代码来源:outlinertreewidget.py

示例2: setEditorData

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
 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,代码行数:15,代码来源:outlinertreewidget.py

示例3: setEditorData

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
 def setEditorData(self, editor: QWidget, index: QModelIndex):
     editor.blockSignals(True)
     item = index.model().data(index)
     try:
         indx = self.items.index(item) if item in self.items else int(item)
         editor.setCurrentIndex(indx)
     except ValueError:
         pass
     editor.blockSignals(False)
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:11,代码来源:ComboBoxDelegate.py

示例4: paint

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
 def paint(self, painter: QPainter,
                 option: QStyleOptionViewItem,
                 model_index: QModelIndex):
     """
     Args:
         painter: Description
         option: Description
         model_index: Description
     """
     # row = model_index.row()
     column = model_index.column()
     if column == 0:  # Part Name
         option.displayAlignment = Qt.AlignVCenter
         QStyledItemDelegate.paint(self, painter, option, model_index)
     if column == 1:  # Visibility
         value = model_index.model().data(model_index, Qt.EditRole)
         data_type = type(value)
         if data_type is str:
             # print("val", value)
             if COLOR_PATTERN.search(value):
                 # print("found color")
                 element = _QCOMMONSTYLE.PE_IndicatorCheckBox
                 styleoption = QStyleOptionViewItem()
                 styleoption.palette.setBrush(QPalette.Button, getBrushObj(value))
                 styleoption.rect = QRect(option.rect)
                 _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
             option.displayAlignment = Qt.AlignVCenter
             QStyledItemDelegate.paint(self, painter, option, model_index)
         elif data_type is int:
             option.displayAlignment = Qt.AlignVCenter
             QStyledItemDelegate.paint(self, painter, option, model_index)
         elif data_type is float:
             option.displayAlignment = Qt.AlignVCenter
             QStyledItemDelegate.paint(self, painter, option, model_index)
         elif data_type is bool:
             element = _QCOMMONSTYLE.PE_IndicatorCheckBox
             styleoption = QStyleOptionButton()
             styleoption.rect = QRect(option.rect)
             checked = value
             styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
             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)
     else:
         QStyledItemDelegate.paint(self, painter, option, model_index)
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:50,代码来源:propertyeditorwidget.py

示例5: paint

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [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

示例6: configureEditor

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
    def configureEditor(self, parent_qw: QWidget,
                            option: QStyleOptionViewItem,
                            model_index: QModelIndex) -> QWidget:
        """
        Args:
            parent_qw: Description
            option Description
            model_index: Description

        Returns:
            the widget used to edit the item specified by index for editing

        Raises:
            NotImplementedError: Description
        """
        cn_m = self.outlineViewObj()
        key = self.key()
        if key == 'name':
            return QLineEdit(parent_qw)
        elif key not in cn_m.editable_properties:
            return None
        if self.is_enum:
            editor = QComboBox(parent_qw)
            for val in ENUM_NAMES[key]:
                editor.addItem(val)
        else:
            data_type = type(model_index.model().data(model_index, Qt.DisplayRole))
            if data_type is str:
                editor = QLineEdit(parent_qw)
            elif data_type is int:
                editor = QSpinBox(parent_qw)
                editor.setRange(-359, 359)
            elif data_type is float:
                editor = QDoubleSpinBox(parent_qw)
                editor.setDecimals(0)
                editor.setRange(-359, 359)
            elif data_type is bool:
                editor = QCheckBox(parent_qw)
            elif isinstance(None, data_type):
                return None
            else:
                raise NotImplementedError
        return editor
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:45,代码来源:cnpropertyitem.py

示例7: updateEditorGeometry

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
 def updateEditorGeometry(self,  editor: QWidget,
                                 option: QStyleOptionViewItem,
                                 model_index: QModelIndex):
     """
     Args:
         editor: Description
         option: Description
         model_index: Description
     """
     column = model_index.column()
     if column == 0:
         editor.setGeometry(option.rect)
     elif column == 1:
         value = model_index.model().data(model_index, Qt.EditRole)
         data_type = type(value)
         if data_type is bool:
             rect = QRect(option.rect)
             delta = option.rect.width() / 2 - 9
             rect.setX(option.rect.x() + delta)  # Hack to center the checkbox
             editor.setGeometry(rect)
         else:
             editor.setGeometry(option.rect)
     else:
         QStyledItemDelegate.updateEditorGeometry(self, editor, option, model_index)
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:26,代码来源:propertyeditorwidget.py

示例8: setEditorData

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
 def setEditorData(self, editor: SectionComboBox, index: QModelIndex):
     editor.blockSignals(True)
     item = index.model().data(index)
     editor.setCurrentText(item)
     editor.blockSignals(False)
开发者ID:jopohl,项目名称:urh,代码行数:7,代码来源:SectionComboBoxDelegate.py

示例9: setEditorData

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
 def setEditorData(self, editor: QCheckBox, index: QModelIndex):
     editor.blockSignals(True)
     editor.setChecked(index.model().data(index))
     self.enabled = editor.isChecked()
     editor.blockSignals(False)
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:7,代码来源:CheckBoxDelegate.py

示例10: textEditView

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
class textEditView(QTextEdit):
    def __init__(self, parent=None, index=None, html=None, spellcheck=None,
                 highlighting=False, dict="", autoResize=False):
        QTextEdit.__init__(self, parent)
        self._column = Outline.text
        self._index = None
        self._indexes = None
        self._model = None
        self._placeholderText = self.placeholderText()
        self._updating = False
        self._item = None
        self._highlighting = highlighting
        self._textFormat = "text"
        self.setAcceptRichText(False)
        # When setting up a theme, this becomes true.
        self._fromTheme = False
        self._themeData = None
        self._highlighterClass = BasicHighlighter

        if spellcheck is None:
            spellcheck = settings.spellcheck

        self.spellcheck = spellcheck
        self.currentDict = dict if dict else settings.dict
        self._defaultFontSize = qApp.font().pointSize()
        self.highlighter = None
        self.setAutoResize(autoResize)
        self._defaultBlockFormat = QTextBlockFormat()
        self._defaultCharFormat = QTextCharFormat()
        self.highlightWord = ""
        self.highligtCS = False
        self._dict = None
        # self.document().contentsChanged.connect(self.submit, F.AUC)

        # Submit text changed only after 500ms without modifications
        self.updateTimer = QTimer()
        self.updateTimer.setInterval(500)
        self.updateTimer.setSingleShot(True)
        self.updateTimer.timeout.connect(self.submit)
        # self.updateTimer.timeout.connect(lambda: print("Timeout"))

        self.updateTimer.stop()
        self.document().contentsChanged.connect(self.updateTimer.start, F.AUC)
        # self.document().contentsChanged.connect(lambda: print("Document changed"))

        # self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))

        self.setEnabled(False)

        if index:
            self.setCurrentModelIndex(index)

        elif html:
            self.document().setHtml(html)
            self.setReadOnly(True)

        # Spellchecking
        if enchant and self.spellcheck:
            try:
                self._dict = enchant.Dict(self.currentDict if self.currentDict
                                          else self.getDefaultLocale())
            except enchant.errors.DictNotFoundError:
                self.spellcheck = False

        else:
            self.spellcheck = False

        if self._highlighting and not self.highlighter:
            self.highlighter = self._highlighterClass(self)
            self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)

    def getDefaultLocale(self):
        default_locale = enchant.get_default_language()
        if default_locale is None:
            default_locale = QLocale.system().name()
        if default_locale is None:
            default_locale = enchant.list_dicts()[0][0]

        return default_locale

    def setModel(self, model):
        self._model = model
        try:
            self._model.dataChanged.connect(self.update, F.AUC)
        except TypeError:
            pass

    def setColumn(self, col):
        self._column = col

    def setHighlighting(self, val):
        self._highlighting = val

    def setDefaultBlockFormat(self, bf):
        self._defaultBlockFormat = bf
        if self.highlighter:
            self.highlighter.setDefaultBlockFormat(bf)

    def setCurrentModelIndex(self, index):
        self._indexes = None
#.........这里部分代码省略.........
开发者ID:olivierkes,项目名称:manuskript,代码行数:103,代码来源:textEditView.py

示例11: textEditView

# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import model [as 别名]
class textEditView(QTextEdit):
    def __init__(self, parent=None, index=None, html=None, spellcheck=True, highlighting=False, dict="",
                 autoResize=False):
        QTextEdit.__init__(self, parent)
        self._column = Outline.text.value
        self._index = None
        self._indexes = None
        self._model = None
        self._placeholderText = self.placeholderText()
        self._updating = False
        self._item = None
        self._highlighting = highlighting
        self._textFormat = "text"
        self.setAcceptRichText(False)
        # When setting up a theme, this becomes true.
        self._fromTheme = False

        self.spellcheck = spellcheck
        self.currentDict = dict if dict else settings.dict
        self.highlighter = None
        self.setAutoResize(autoResize)
        self._defaultBlockFormat = QTextBlockFormat()
        self._defaultCharFormat = QTextCharFormat()
        self.highlightWord = ""
        self.highligtCS = False
        self.defaultFontPointSize = qApp.font().pointSize()
        self._dict = None
        # self.document().contentsChanged.connect(self.submit, AUC)

        # Submit text changed only after 500ms without modifications
        self.updateTimer = QTimer()
        self.updateTimer.setInterval(500)
        self.updateTimer.setSingleShot(True)
        self.updateTimer.timeout.connect(self.submit)
        # self.updateTimer.timeout.connect(lambda: print("Timeout"))

        self.updateTimer.stop()
        self.document().contentsChanged.connect(self.updateTimer.start, AUC)
        # self.document().contentsChanged.connect(lambda: print("Document changed"))

        # self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))

        self.setEnabled(False)

        if index:
            self.setCurrentModelIndex(index)

        elif html:
            self.document().setHtml(html)
            self.setReadOnly(True)

        # Spellchecking
        if enchant and self.spellcheck:
            try:
                self._dict = enchant.Dict(self.currentDict if self.currentDict else enchant.get_default_language())
            except enchant.errors.DictNotFoundError:
                self.spellcheck = False

        else:
            self.spellcheck = False

        if self._highlighting and not self.highlighter:
            self.highlighter = basicHighlighter(self)
            self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)

    def setModel(self, model):
        self._model = model
        try:
            self._model.dataChanged.connect(self.update, AUC)
        except TypeError:
            pass
        try:
            self._model.rowsAboutToBeRemoved.connect(self.rowsAboutToBeRemoved, AUC)
        except TypeError:
            pass

    def setColumn(self, col):
        self._column = col

    def setHighlighting(self, val):
        self._highlighting = val

    def setDefaultBlockFormat(self, bf):
        self._defaultBlockFormat = bf
        if self.highlighter:
            self.highlighter.setDefaultBlockFormat(bf)

    def setCurrentModelIndex(self, index):
        self._indexes = None
        if index.isValid():
            self.setEnabled(True)
            if index.column() != self._column:
                index = index.sibling(index.row(), self._column)
            self._index = index

            self.setPlaceholderText(self._placeholderText)

            if not self._model:
                self.setModel(index.model())

#.........这里部分代码省略.........
开发者ID:TenKeyAngle,项目名称:manuskript,代码行数:103,代码来源:textEditView.py


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