當前位置: 首頁>>代碼示例>>Python>>正文


Python QtWidgets.QStyledItemDelegate方法代碼示例

本文整理匯總了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() 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:22,代碼來源:completiondelegate.py

示例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] 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:30,代碼來源:completiondelegate.py

示例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 
開發者ID:ynvb,項目名稱:DIE,代碼行數:5,代碼來源:FunctionViewEx.py

示例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) 
開發者ID:FrancescoCeruti,項目名稱:linux-show-player,代碼行數:13,代碼來源:fade_combobox.py

示例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 
開發者ID:reuterbal,項目名稱:photobooth,代碼行數:16,代碼來源:Frames.py

示例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 
開發者ID:reuterbal,項目名稱:photobooth,代碼行數:33,代碼來源:Frames.py

示例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) 
開發者ID:szsdk,項目名稱:quick,代碼行數:9,代碼來源:quick.py

示例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) 
開發者ID:BasioMeusPuga,項目名稱:Lector,代碼行數:44,代碼來源:delegates.py


注:本文中的PyQt5.QtWidgets.QStyledItemDelegate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。