Пример #1
0
 def paintEvent(self, _event) -> None:
     painter = QStylePainter(self)
     option = QStyleOptionComboBox()
     self.initStyleOption(option)
     painter.drawComplexControl(QStyle.CC_ComboBox, option)
     foreground = self.currentData(Qt.ForegroundRole)
     if isinstance(foreground, (QBrush, QColor)):
         foreground = QBrush(foreground)
         if foreground.style() != Qt.NoBrush:
             # some styles take WindowText some just use current pen?
             option.palette.setBrush(QPalette.WindowText, foreground)
             option.palette.setBrush(QPalette.ButtonText, foreground)
             option.palette.setBrush(QPalette.Text, foreground)
             painter.setPen(QPen(foreground, painter.pen().widthF()))
     font = self.currentData(Qt.FontRole)
     if isinstance(font, QFont):
         option.fontMetrics = QFontMetrics(font)
         painter.setFont(font)
     painter.drawControl(QStyle.CE_ComboBoxLabel, option)
Пример #2
0
    def paint(self, painter, option, _widget=None):
        painter.save()
        path = self.path()
        brush = QBrush(self.brush())
        pen = QPen(self.pen())

        if option.state & QStyle.State_Selected:
            pen.setColor(Qt.red)
            brush.setStyle(Qt.DiagCrossPattern)
            brush.setColor(QColor(40, 40, 40, 100))

        elif option.state & QStyle.State_MouseOver:
            pen.setColor(Qt.blue)

        if option.state & QStyle.State_MouseOver:
            brush.setColor(QColor(100, 100, 100, 100))
            if brush.style() == Qt.NoBrush:
                # Make sure the highlight is actually visible.
                brush.setStyle(Qt.SolidPattern)

        painter.setPen(pen)
        painter.setBrush(brush)
        painter.drawPath(path)
        painter.restore()
Пример #3
0
    def paint(self, painter, option, widget=None):
        painter.save()
        path = self.path()
        brush = QBrush(self.brush())
        pen = QPen(self.pen())

        if option.state & QStyle.State_Selected:
            pen.setColor(Qt.red)
            brush.setStyle(Qt.DiagCrossPattern)
            brush.setColor(QColor(40, 40, 40, 100))

        elif option.state & QStyle.State_MouseOver:
            pen.setColor(Qt.blue)

        if option.state & QStyle.State_MouseOver:
            brush.setColor(QColor(100, 100, 100, 100))
            if brush.style() == Qt.NoBrush:
                # Make sure the highlight is actually visible.
                brush.setStyle(Qt.SolidPattern)

        painter.setPen(pen)
        painter.setBrush(brush)
        painter.drawPath(path)
        painter.restore()