Python PyQt5.QtWidgets.QStyleOptionViewItem() Examples
The following are 13
code examples of PyQt5.QtWidgets.QStyleOptionViewItem().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt5.QtWidgets
, or try the search function
.
Example #1
Source File: sources_dock.py From kite with GNU General Public License v3.0 | 6 votes |
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()
Example #2
Source File: ComboBoxDelegate.py From urh with GNU General Public License v3.0 | 6 votes |
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)
Example #3
Source File: ComboBoxDelegate.py From urh with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: angrysearch.py From ANGRYsearch with GNU General Public License v2.0 | 5 votes |
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()
Example #5
Source File: sources_dock.py From kite with GNU General Public License v3.0 | 5 votes |
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())
Example #6
Source File: notification_center_widget.py From parsec-cloud with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #7
Source File: foldArea.py From Hydra with GNU General Public License v3.0 | 5 votes |
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()
Example #8
Source File: treeview_model.py From CvStudio with MIT License | 5 votes |
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
Example #9
Source File: CheckBoxDelegate.py From urh with GNU General Public License v3.0 | 5 votes |
def createEditor(self, parent: QWidget, option: QStyleOptionViewItem, index: QModelIndex): editor = QCheckBox(parent) editor.stateChanged.connect(self.stateChanged) return editor
Example #10
Source File: ComboBoxDelegate.py From urh with GNU General Public License v3.0 | 5 votes |
def updateEditorGeometry(self, editor: QWidget, option: QStyleOptionViewItem, index: QModelIndex): editor.setGeometry(option.rect)
Example #11
Source File: SpinBoxDelegate.py From urh with GNU General Public License v3.0 | 5 votes |
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
Example #12
Source File: SectionComboBoxDelegate.py From urh with GNU General Public License v3.0 | 5 votes |
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
Example #13
Source File: SectionComboBoxDelegate.py From urh with GNU General Public License v3.0 | 5 votes |
def updateEditorGeometry(self, editor: QWidget, option: QStyleOptionViewItem, index: QModelIndex): editor.setGeometry(option.rect)