Exemple #1
0
 def paint(self, painter, option, index):
     value = index.data(Qt.DisplayRole)
     style = QApplication.style()
     opt = QStyleOptionComboBox()
     opt.text = str(value)
     opt.rect = option.rect
     style.drawComplexControl(QStyle.CC_ComboBox, opt, painter)
     QItemDelegate.paint(self, painter, option, index)
Exemple #2
0
    def paintEvent(self, event):
        opt = QStyleOptionComboBox()
        self.initStyleOption(opt)
        p = QStylePainter(self)
        p.drawComplexControl(QStyle.CC_ComboBox, opt)

        text_rect = self.style().subControlRect(QStyle.CC_ComboBox, opt,
                                                QStyle.SC_ComboBoxEditField,
                                                self)
        opt.currentText = p.fontMetrics().elidedText(opt.currentText,
                                                     Qt.ElideLeft,
                                                     text_rect.width())
        p.drawControl(QStyle.CE_ComboBoxLabel, opt)
Exemple #3
0
    def paintEvent(self, event):
        """
        A customized paint event

        .. note::

            Global styling such as style sheets can be combined with a custom
            paint event using the ``QStylePainter``. In this case we customize
            the text displayed for our combo box without losing the assigned style.
        """
        options = QStyleOptionComboBox()
        options.initFrom(self)

        # Customize the painting options to control the way the combo box is
        # painted by QStyle.
        options.currentText = 'MY CUSTOM TEXT'
        options.frame = False

        # Use the QStylePainter to ensure styling is still applied.
        painter = QStylePainter(self)
        painter.drawComplexControl(QStyle.CC_ComboBox, options)
        painter.drawControl(QStyle.CE_ComboBoxLabel, options)