本文整理汇总了Python中PyQt5.QtWidgets.QStyledItemDelegate方法的典型用法代码示例。如果您正苦于以下问题:Python QtWidgets.QStyledItemDelegate方法的具体用法?Python QtWidgets.QStyledItemDelegate怎么用?Python QtWidgets.QStyledItemDelegate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QStyledItemDelegate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
def paint(self, painter, option, index):
"""Override the QStyledItemDelegate paint function.
Args:
painter: QPainter * painter
option: const QStyleOptionViewItem & option
index: const QModelIndex & index
"""
self._painter = painter
self._painter.save()
self._opt = QStyleOptionViewItem(option)
self.initStyleOption(self._opt, index)
self._style = self._opt.widget.style()
self._draw_background()
self._draw_icon()
self._draw_text(index)
self._draw_focus_rect()
self._painter.restore()
示例2: sizeHint
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
def sizeHint(self, option, index):
"""Override sizeHint of QStyledItemDelegate.
Return the cell size based on the QTextDocument size, but might not
work correctly yet.
Args:
option: const QStyleOptionViewItem & option
index: const QModelIndex & index
Return:
A QSize with the recommended size.
"""
value = index.data(Qt.SizeHintRole)
if value is not None:
return value
self._opt = QStyleOptionViewItem(option)
self.initStyleOption(self._opt, index)
self._style = self._opt.widget.style()
self._get_textdoc(index)
assert self._doc is not None
docsize = self._doc.size().toSize()
size = self._style.sizeFromContents(QStyle.CT_ItemViewItem, self._opt,
docsize, self._opt.widget)
qtutils.ensure_valid(size)
return size + QSize(10, 3) # type: ignore[operator]
示例3: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
def __init__(self, parent):
QtWidgets.QStyledItemDelegate.__init__(self, parent)
self.parent = parent
示例4: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
def __init__(self, *args, mode=Mode.FadeOut, **kwargs):
super().__init__(*args, **kwargs)
self.setItemDelegate(QStyledItemDelegate())
if mode == self.Mode.FadeIn:
items = self.FadeInIcons
else:
items = self.FadeOutIcons
for key in sorted(items.keys()):
self.addItem(items[key], translate('Fade', key), key)
示例5: createModuleComboBox
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
def createModuleComboBox(self, module_list, current_module):
cb = QtWidgets.QComboBox()
for m in module_list:
cb.addItem(m[0])
idx = [x for x, m in enumerate(module_list) if m[0] == current_module]
cb.setCurrentIndex(idx[0] if len(idx) > 0 else -1)
# Fix bug in Qt to allow changing the items in a stylesheet
delegate = QtWidgets.QStyledItemDelegate()
cb.setItemDelegate(delegate)
return cb
示例6: createCameraSettings
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
def createCameraSettings(self):
self.init('Camera')
module = self.createModuleComboBox(camera.modules,
self._cfg.get('Camera', 'module'))
self.add('Camera', 'module', module)
self.rot_vals_ = (0, 90, 180, 270)
cur_rot = self._cfg.getInt('Camera', 'rotation')
rotation = QtWidgets.QComboBox()
for r in self.rot_vals_:
rotation.addItem(str(r))
idx = [x for x, r in enumerate(self.rot_vals_) if r == cur_rot]
rotation.setCurrentIndex(idx[0] if len(idx) > 0 else -1)
# Fix bug in Qt to allow changing the items in a stylesheet
delegate = QtWidgets.QStyledItemDelegate()
rotation.setItemDelegate(delegate)
self.add('Camera', 'rotation', rotation)
layout = QtWidgets.QFormLayout()
layout.addRow(_('Camera module:'), module)
layout.addRow(_('Camera rotation:'), rotation)
widget = QtWidgets.QWidget()
widget.setLayout(layout)
return widget
示例7: setModelData
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
def setModelData(self, editor, model, index):
data_str = editor.text()
if data_str == "" or data_str is None:
model.setData(index, QtGui.QBrush(QtGui.QColor(_gstyle.placehoder_color)), role=QtCore.Qt.ForegroundRole)
else:
model.setData(index, QtGui.QBrush(QtGui.QColor(_gstyle.text_color)), role=QtCore.Qt.ForegroundRole)
QtWidgets.QStyledItemDelegate.setModelData(self, editor, model, index)
示例8: paint
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
def paint(self, painter, option, index):
# This is a hint for the future
# Color icon slightly red
# if option.state & QtWidgets.QStyle.State_Selected:
# painter.fillRect(option.rect, QtGui.QColor().fromRgb(255, 0, 0, 20))
option = option.__class__(option)
file_exists = index.data(QtCore.Qt.UserRole + 5)
position_percent = index.data(QtCore.Qt.UserRole + 7)
# The shadow pixmap currently is set to 420 x 600
# Only draw the cover shadow in case the setting is enabled
if self.parent.settings['cover_shadows']:
shadow_pixmap = QtGui.QPixmap()
shadow_pixmap.load(':/images/gray-shadow.png')
shadow_pixmap = shadow_pixmap.scaled(160, 230, QtCore.Qt.IgnoreAspectRatio)
shadow_x = option.rect.topLeft().x() + 10
shadow_y = option.rect.topLeft().y() - 5
painter.setOpacity(.7)
painter.drawPixmap(shadow_x, shadow_y, shadow_pixmap)
painter.setOpacity(1)
if not file_exists:
painter.setOpacity(.7)
QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
painter.setOpacity(1)
read_icon = pie_chart.pixmapper(
-1, None, self.parent.settings['consider_read_at'], 36)
x_draw = option.rect.bottomRight().x() - 30
y_draw = option.rect.bottomRight().y() - 35
painter.drawPixmap(x_draw, y_draw, read_icon)
return
QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
if position_percent:
read_icon = pie_chart.pixmapper(
position_percent, self.temp_dir, self.parent.settings['consider_read_at'], 36)
x_draw = option.rect.bottomRight().x() - 30
y_draw = option.rect.bottomRight().y() - 35
painter.drawPixmap(x_draw, y_draw, read_icon)