예제 #1
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)
예제 #2
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)