示例#1
0
 def drawControl(self,
                 element,
                 style_option: QStyleOption,
                 painter: QPainter,
                 widget=None):
     """TODO"""
     QProxyStyle.drawControl(self, element, style_option, painter, widget)
示例#2
0
 def drawControl(self, element, opt, painter, widget):
     if element == QStyle.CE_TabBarTabLabel:
         ic = self.pixelMetric(QStyle.PM_TabBarIconSize)
         r = QRect(opt.rect)
         w =  0 if opt.icon.isNull() else opt.rect.width() + self.pixelMetric(QStyle.PM_TabBarIconSize)
         r.setHeight(opt.fontMetrics.width(opt.text) + w)
         r.moveBottom(opt.rect.bottom())
         opt.rect = r
     QProxyStyle.drawControl(self, element, opt, painter, widget)
 def drawControl(self,
                 element: QStyle.ControlElement,
                 opt: 'QStyleOption',
                 painter: QtGui.QPainter,
                 widget: typing.Optional[QWidget] = ...) -> None:
     if element == QStyle.CE_TabBarTabLabel:
         ic = self.pixelMetric(QStyle.PM_TabBarIconSize)
         r = QtCore.QRect(opt.rect)
         w = 0 if opt.icon.isNull() else opt.rect.width(
         ) + self.pixelMetric(QStyle.PM_TabBarIconSize)
         r.setHeight(opt.fontMetrics.width(opt.text) + w)
         r.moveBottom(opt.rect.bottom())
         opt.rect = r
     QProxyStyle.drawControl(self, element, opt, painter, widget)
示例#4
0
    def drawControl(self, element, opt, painter, widget):
        """elif element == QStyle.CE_PushButtonBevel:
            # States
            is_down = (opt.state & STATE_SUNKEN) | (opt.state & STATE_ON)
            hovered = opt.state & STATE_ENABLED and opt.state & STATE_MOUSEOVER
            has_focus = opt.state & STATE_HASFOCUS

            rect = opt.rect
            btn_color = opt.palette.button().color()
            painter.setPen(btn_color)
            painter.setRenderHint(QPainter.Antialiasing)
            path = QPainterPath()
            path.addRoundedRect(QRectF(rect), 3, 3)
            if is_down:
                painter.setBrush(btn_color.darker(115))
            elif has_focus:
                painter.setBrush(btn_color.lighter(130))
            elif hovered:
                grad = QLinearGradient(rect.topLeft(), rect.bottomLeft())
                grad.setColorAt(0.6, btn_color)
                grad.setColorAt(1, btn_color.lighter(120))
                painter.setBrush(grad)
            else:
                painter.setBrush(btn_color)
            painter.drawPath(path)"""
        if element == QStyle.CE_ComboBoxLabel:
            cb = opt
            painter.save()
            edit_rect = self.subControlRect(QStyle.CC_ComboBox, cb,
                                            QStyle.SC_ComboBoxEditField,
                                            widget)
            # Draw icon
            if not cb.currentIcon.isNull():
                if cb.state & STATE_ENABLED:
                    mode = QIcon.Normal
                else:
                    mode = QIcon.Disabled
                pixmap = cb.currentIcon.pixmap(cb.iconSize, mode)
                icon_rect = QRect(cb.rect)
                icon_rect.setWidth(cb.iconSize.width() + 4)
                # icon_rect = self.alignedRect(opt.direction,
                #                             Qt.AlignLeft | Qt.AlignVCenter,
                #                             icon_rect.size(), edit_rect)
                self.drawItemPixmap(painter, icon_rect, Qt.AlignCenter, pixmap)
                # Space between text
                if cb.direction == Qt.RightToLeft:
                    edit_rect.translate(-4, -cb.iconSize.width(), 0)
                else:
                    edit_rect.translate(cb.iconSize.width() + 4, 0)

            edit_rect.adjusted(0, 0, -13, 0)
            # Draw text
            elide_width = edit_rect.width() - opt.fontMetrics.width('**')
            text = opt.fontMetrics.elidedText(cb.currentText, Qt.ElideRight,
                                              elide_width)
            # FIXME: states
            painter.setPen(_COLORS['ComboBoxTextColor'])
            painter.drawText(edit_rect.adjusted(1, 0, -1, 0),
                             Qt.AlignLeft | Qt.AlignVCenter, text)
            painter.restore()
        # TODO: tab with flat style
        # elif element == QStyle.CE_TabBarTabShape:
        #    pass
        elif element == QStyle.CE_ToolBar:
            rect = opt.rect
            # print(widget.property("border"), widget)
            painter.fillRect(rect, _COLORS['ToolButtonColor'])
            if widget.property("border"):
                # painter.setPen(opt.palette.light().color().lighter(150))
                painter.setPen(_COLORS["Border"])
                painter.drawLine(rect.topLeft(), rect.topRight())
            # painter.setPen(_COLORS['Border'])
            # painter.drawLine(opt.rect.topRight(), opt.rect.bottomRight())

        elif element == QStyle.CE_MenuItem:
            painter.save()
            enabled = opt.state & STATE_ENABLED
            item = opt
            item.rect = opt.rect
            pal = opt.palette
            if enabled:
                color = _COLORS['MenuItemEnabled']
            else:
                color = _COLORS['MenuItemDisabled']
            item.palette = pal
            pal.setBrush(QPalette.Text, color)
            QProxyStyle.drawControl(self, element, opt, painter, widget)
            painter.restore()
        elif element == QStyle.CE_MenuBarEmptyArea:
            painter.fillRect(opt.rect, _COLORS['MenuBar'])
            # Draw border
            painter.save()
            # FIXME: color from theme
            painter.setPen(_COLORS['MenuBarBorderColor'])
            painter.drawLine(opt.rect.bottomLeft() + QPointF(.5, .5),
                             opt.rect.bottomRight() + QPointF(.5, .5))
            painter.restore()
        # elif element == QStyle.CE_PushButtonBevel:
        #    painter.setPen(Qt.red)
        #    painter.fillRect(opt.rect, QColor("red"))
        elif element == QStyle.CE_MenuBarItem:
            painter.save()
            act = opt.state & (STATE_SUNKEN | QStyle.State_Selected)
            dis = not (opt.state & STATE_ENABLED)
            painter.fillRect(opt.rect, _COLORS['MenuBar'])
            pal = opt.palette
            item = opt
            item.rect = opt.rect
            if dis:
                color = _COLORS['MenuBarItemDisabled']
            else:
                color = _COLORS['MenuBarItemEnabled']
            pal.setBrush(QPalette.ButtonText, color)
            item.palette = pal
            QCommonStyle.drawControl(self, element, item, painter, widget)
            if act:
                pal = opt.palette
                color = _COLORS['MenuBarHover']
                painter.fillRect(opt.rect, color)
                align = (Qt.AlignCenter | Qt.TextShowMnemonic | Qt.TextDontClip
                         | Qt.TextSingleLine)
                if not self.styleHint(QStyle.SH_UnderlineShortcut, opt,
                                      widget):
                    align |= Qt.TextHideMnemonic
                # FIXME:
                if dis:
                    co = _COLORS['IconDisabledColor']
                else:
                    co = _COLORS['MenuBarTextHover']
                painter.setPen(Qt.NoPen)
                pal.setBrush(QPalette.Text, co)
                self.drawItemText(painter, item.rect, align, pal, not dis,
                                  opt.text, QPalette.Text)
            painter.restore()
        else:
            QProxyStyle.drawControl(self, element, opt, painter, widget)