Python PyQt5.QtWidgets.QStyledItemDelegate() Examples

The following are 8 code examples of PyQt5.QtWidgets.QStyledItemDelegate(). 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: completiondelegate.py    From qutebrowser with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #2
Source File: FunctionViewEx.py    From DIE with MIT License 6 votes vote down vote up
def __init__(self, parent):
        QtWidgets.QStyledItemDelegate.__init__(self, parent)
        self.parent = parent 
Example #3
Source File: completiondelegate.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
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] 
Example #4
Source File: fade_combobox.py    From linux-show-player with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #5
Source File: Frames.py    From photobooth with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #6
Source File: Frames.py    From photobooth with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #7
Source File: quick.py    From quick with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #8
Source File: delegates.py    From Lector with GNU General Public License v3.0 4 votes vote down vote up
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)