本文整理汇总了Python中PyQt5.QtWidgets.QStyledItemDelegate.paint方法的典型用法代码示例。如果您正苦于以下问题:Python QStyledItemDelegate.paint方法的具体用法?Python QStyledItemDelegate.paint怎么用?Python QStyledItemDelegate.paint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStyledItemDelegate
的用法示例。
在下文中一共展示了QStyledItemDelegate.paint方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [as 别名]
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()
示例2: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [as 别名]
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)
示例3: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [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)
示例4: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [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)
示例5: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [as 别名]
def paint(self, painter, option, index):
extra = index.data(Qt.UserRole + 1)
if not extra:
return QStyledItemDelegate.paint(self, painter, option, index)
else:
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.color(QPalette.Inactive, QPalette.Highlight))
title = index.data()
extra = " - {}".format(extra)
painter.drawText(option.rect, Qt.AlignLeft, title)
fm = QFontMetrics(option.font)
w = fm.width(title)
r = QRect(option.rect)
r.setLeft(r.left() + w)
painter.save()
if option.state & QStyle.State_Selected:
painter.setPen(QColor(S.highlightedTextLight))
else:
painter.setPen(QColor(S.textLight))
painter.drawText(r, Qt.AlignLeft, extra)
painter.restore()
示例6: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [as 别名]
def paint(self, painter, option, index):
if index.column() == 2:
button = QStyleOptionButton()
r = option.rect # getting the rect of the cell
x = r.left()
y = r.top()
w = r.width()
h = r.height()
button.rect = QRect(x, y, w, h)
button.text = "X"
button.state = QStyle.State_Enabled;
QApplication.style().drawControl(QStyle.CE_PushButton, button, painter)
else:
QStyledItemDelegate.paint(self, painter, option, index)
示例7: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [as 别名]
def paint(self, painter, option, idx):
painter.save()
# set background color
painter.setPen(QPen(Qt.NoPen))
if idx.column() == 0:
ccode = 245
painter.setBrush(QBrush(QColor(ccode, ccode, ccode)))
else:
painter.setBrush(QBrush(Qt.transparent))
if not idx.parent().isValid():
painter.setBrush(QBrush(QColor(0xFF, 0xDC, 0xA4) ) )
painter.drawRect(option.rect)
# draw the rest
QStyledItemDelegate.paint(self, painter, option, idx)
painter.restore()
示例8: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [as 别名]
def paint(self, painter, option, idx):
new_idx = idx.sibling(idx.row(), 0)
item = self.model.itemFromIndex(new_idx)
if item and item.data(Qt.UserRole) in self.added_node_list:
option.font.setWeight(QFont.Bold)
QStyledItemDelegate.paint(self, painter, option, idx)
示例9: paint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import paint [as 别名]
def paint(self, painter, option, index):
QStyledItemDelegate.paint(self, painter, option, index)