Exemplo n.º 1
0
 def paintEvent(self, event):
     # type: (QPaintEvent) -> None
     p = QStylePainter(self)
     opt = QStyleOptionToolButton()
     self.initStyleOption(opt)
     p.drawComplexControl(QStyle.CC_ToolButton, opt)
     p.end()
Exemplo n.º 2
0
 def paintEvent(self, event):
     """Reimplemented."""
     opt = QStyleOptionComboBox()
     self.initStyleOption(opt)
     painter = QStylePainter(self)
     painter.drawComplexControl(QStyle.CC_ComboBox, opt)
     if not self.__searchline.isVisibleTo(self):
         opt.editable = False
         painter.drawControl(QStyle.CE_ComboBoxLabel, opt)
Exemplo n.º 3
0
 def paintEvent(self, event):
     """Reimplemented."""
     opt = QStyleOptionComboBox()
     self.initStyleOption(opt)
     painter = QStylePainter(self)
     painter.drawComplexControl(QStyle.CC_ComboBox, opt)
     if not self.__searchline.isVisibleTo(self):
         opt.editable = False
         painter.drawControl(QStyle.CE_ComboBoxLabel, opt)
Exemplo n.º 4
0
 def paintEvent(self, event):
     p = QStylePainter(self)
     opt = QStyleOptionToolButton()
     self.initStyleOption(opt)
     if self.__text:
         # Replace the text
         opt.text = self.__text
     p.drawComplexControl(QStyle.CC_ToolButton, opt)
     p.end()
Exemplo n.º 5
0
 def paintEvent(self, event):
     p = QStylePainter(self)
     opt = QStyleOptionToolButton()
     self.initStyleOption(opt)
     if self.__text:
         # Replace the text
         opt.text = self.__text
     p.drawComplexControl(QStyle.CC_ToolButton, opt)
     p.end()
    def paintEvent(self, event):
        opt = QStyleOptionToolButton()
        self.initStyleOption(opt)
        if self.__showMenuIndicator and self.isChecked():
            opt.features |= QStyleOptionToolButton.HasMenu
        if self.__flat:
            # Use default widget background/border styling.
            StyledWidget_paintEvent(self, event)

            p = QStylePainter(self)
            p.drawControl(QStyle.CE_ToolButtonLabel, opt)
        else:
            p = QStylePainter(self)
            p.drawComplexControl(QStyle.CC_ToolButton, opt)
Exemplo n.º 7
0
    def paintEvent(self, event):
        opt = QStyleOptionToolButton()
        self.initStyleOption(opt)
        if self.__showMenuIndicator and self.isChecked():
            opt.features |= QStyleOptionToolButton.HasMenu
        if self.__flat:
            # Use default widget background/border styling.
            StyledWidget_paintEvent(self, event)

            p = QStylePainter(self)
            p.drawControl(QStyle.CE_ToolButtonLabel, opt)
        else:
            p = QStylePainter(self)
            p.drawComplexControl(QStyle.CC_ToolButton, opt)
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def paintEvent(self, event):
        # based on
        # https://github.com/qt/qtbase/blob/f40dbe0d0b54ce83d2168e82905cf4f75059a841/src/widgets/widgets/qslider.cpp#L315
        # https://github.com/enthought/traitsui/blob/master/traitsui/qt4/extra/range_slider.py
        painter = QStylePainter(self)
        minpos = self._min_position
        maxpos = self._max_position

        # Draw the groove
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        # Draw empty grove
        opt.sliderPosition = opt.minimum
        opt.subControls = QStyle.SC_SliderGroove
        if self.tickPosition() != self.NoTicks:
            opt.subControls |= QStyle.SC_SliderTickmarks
        painter.drawComplexControl(QStyle.CC_Slider, opt)
        # Draw the highlighted part on top
        # Qt4.8 and Qt5.3 draw the highlighted groove in a weird way because they
        # transpose opt.rect. Qt5.7 works fine.
        if QT_VERSION_STR >= '5.7.0':
            opt.subControls = QStyle.SC_SliderGroove
            opt.sliderPosition = opt.maximum
            if self.orientation() == Qt.Horizontal:
                _w = opt.rect.width() / opt.maximum
                x = round(_w * minpos)
                w = round(_w * (maxpos - minpos))
                opt.rect = QRect(x, 0, w, opt.rect.height())
            else:
                _h = opt.rect.height() / opt.maximum
                y = round(_h * minpos)
                h = round(_h * (maxpos - minpos))
                opt.rect = QRect(0, y, opt.rect.width(), h)
            painter.drawComplexControl(QStyle.CC_Slider, opt)

        # Draw the handles
        for i, position in enumerate((minpos, maxpos)):
            opt = QStyleOptionSlider()
            self.initStyleOption(opt)
            opt.subControls = QStyle.SC_SliderHandle

            if self.__pressed_control and (self.__active_slider == i or
                                           self.__active_slider < 0):
                opt.activeSubControls = self.__pressed_control
                opt.state |= QStyle.State_Sunken
            else:
                opt.activeSubControls = self.__hovered_control

            opt.sliderPosition = position
            opt.sliderValue = position
            painter.drawComplexControl(QStyle.CC_Slider, opt)
Exemplo n.º 10
0
    def paintEvent(self, event):
        # based on
        # https://github.com/qt/qtbase/blob/f40dbe0d0b54ce83d2168e82905cf4f75059a841/src/widgets/widgets/qslider.cpp#L315
        # https://github.com/enthought/traitsui/blob/master/traitsui/qt4/extra/range_slider.py
        painter = QStylePainter(self)
        minpos = self.__min_position
        maxpos = self.__max_position

        # Draw the groove
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        # Draw empty grove
        opt.sliderPosition = opt.minimum
        opt.subControls = QStyle.SC_SliderGroove
        if self.tickPosition() != self.NoTicks:
            opt.subControls |= QStyle.SC_SliderTickmarks
        painter.drawComplexControl(QStyle.CC_Slider, opt)
        # Draw the highlighted part on top
        # Qt4.8 and Qt5.3 draw the highlighted groove in a weird way because they
        # transpose opt.rect. Qt5.7 works fine.
        if QT_VERSION_STR >= '5.7.0':
            opt.subControls = QStyle.SC_SliderGroove
            opt.sliderPosition = opt.maximum
            if self.orientation() == Qt.Horizontal:
                _w = opt.rect.width() / opt.maximum
                x = round(_w * minpos)
                w = round(_w * (maxpos - minpos))
                opt.rect = QRect(x, 0, w, opt.rect.height())
            else:
                _h = opt.rect.height() / opt.maximum
                y = round(_h * minpos)
                h = round(_h * (maxpos - minpos))
                opt.rect = QRect(0, y, opt.rect.width(), h)
            painter.drawComplexControl(QStyle.CC_Slider, opt)

        # Draw the handles
        for i, position in enumerate((minpos, maxpos)):
            opt = QStyleOptionSlider()
            self.initStyleOption(opt)
            opt.subControls = QStyle.SC_SliderHandle

            if self.__pressed_control and (self.__active_slider == i or
                                           self.__active_slider < 0):
                opt.activeSubControls = self.__pressed_control
                opt.state |= QStyle.State_Sunken
            else:
                opt.activeSubControls = self.__hovered_control

            opt.sliderPosition = position
            opt.sliderValue = position
            painter.drawComplexControl(QStyle.CC_Slider, opt)
Exemplo n.º 11
0
    def paintEvent(self, e):
        #print("hover: ",self._hover,",press: ",self._press)
        painter = QStylePainter(self)

        # prepare the drawing options
        # for drawing slider groove
        opt = QStyleOptionSlider()
        opt.initFrom(self)

        opt.subControls = QStyle.SC_SliderGroove

        opt.maximum = self.__steps
        opt.minimum = 0
        opt.orientation = self.orientation()
        opt.sliderPosition = self.__position0
        opt.sliderValue = self.__value0

        if self._tickList is not None:
            opt.tickPosition = QSlider.TicksBelow
        else:
            opt.tickPosition = QSlider.NoTicks

        handleWidth = self._handleWidth
        measureWidth = self.width() - handleWidth - handleWidth

        painter.drawComplexControl(QStyle.CC_Slider, opt)

        # draw tickmarks
        if self._tickList is not None:
            painter.drawPixmap(self._handleWidth,
                               self.height() - self._tickHeight,
                               self._tickImage)

        # handle colors
        colorPRESS = QColor(204, 204, 204)
        colorHOVER = QColor(23, 23, 23)
        colorNORMAL = QColor(0, 122, 217) if self.isEnabled() else colorPRESS

        handleHeight = self.height(
        ) if self._tickList is None else self.height() - self._tickHeight

        # draw handle 0
        if self._press in {0, 2}:
            color = colorPRESS
        elif self._hover == 0:
            color = colorHOVER
        else:
            color = colorNORMAL
        self._rects[0] = r0 = QRect(
            self.__position0 / self.__steps * measureWidth, 0, handleWidth,
            handleHeight)
        painter.fillRect(self._rects[0], color)

        # draw handle 1
        if self._press in {1, 2}:
            color = colorPRESS
        elif self._hover == 1:
            color = colorHOVER
        else:
            color = colorNORMAL

        self._rects[1] = r1 = QRect(
            self.__position1 / self.__steps * measureWidth + handleWidth, 0,
            handleWidth, handleHeight)
        painter.fillRect(self._rects[1], color)

        # draw inner handle
        if self._press == 2 or not self.isEnabled():
            color = QColor(0, 0, 0, 15)
        elif self._hover == 2:
            color = QColor(0, 61, 108, 63)
        else:
            color = QColor(0, 122, 217, 63)

        self._rects[2] = QRect(r0.left(), r0.top(),
                               r1.right() - r0.left() + 1, handleHeight)

        painter.fillRect(self._rects[2], color)