def drawIndicatorIcon(palette, style):
    pix = QPixmap(14, 14)
    pix.fill(Qt.transparent)
    branchOption = QStyleOption()
    #r = QRect(QPoint(0, 0), pix.size())
    branchOption.rect = QRect(2, 2, 9, 9) ## ### hardcoded in qcommonstyle.cpp
    branchOption.palette = palette
    branchOption.state = QStyle.State_Children

    p = QPainter()
    ## Draw closed state
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()
    rc = QIcon(pix)
    rc.addPixmap(pix, QIcon.Selected, QIcon.Off)
    ## Draw opened state
    branchOption.state |= QStyle.State_Open
    pix.fill(Qt.transparent)
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()

    rc.addPixmap(pix, QIcon.Normal, QIcon.On)
    rc.addPixmap(pix, QIcon.Selected, QIcon.On)
    return rc
Ejemplo n.º 2
0
def drawIndicatorIcon(palette, style):
    pix = QPixmap(14, 14)
    pix.fill(Qt.transparent)
    branchOption = QStyleOption()
    #r = QRect(QPoint(0, 0), pix.size())
    branchOption.rect = QRect(2, 2, 9, 9) ## ### hardcoded in qcommonstyle.cpp
    branchOption.palette = palette
    branchOption.state = QStyle.State_Children

    p = QPainter()
    ## Draw closed state
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()
    rc = QIcon(pix)
    rc.addPixmap(pix, QIcon.Selected, QIcon.Off)
    ## Draw opened state
    branchOption.state |= QStyle.State_Open
    pix.fill(Qt.transparent)
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()

    rc.addPixmap(pix, QIcon.Normal, QIcon.On)
    rc.addPixmap(pix, QIcon.Selected, QIcon.On)
    return rc
Ejemplo n.º 3
0
 def paintEvent(self, event):
     painter = QPainter(self)
     option = QStyleOption()
     option.rect = self.rect()
     option.state = QStyle.State_Horizontal
     option.palette = self.palette()
     self.style().drawPrimitive(QStyle.PE_IndicatorToolBarSeparator, option,
                                painter, self)
Ejemplo n.º 4
0
    def drawComplexControl(
        self,
        cc: QStyle.ComplexControl,
        opt: QStyleOptionComplex,
        p: QPainter,
        widget: QWidget,
    ):

        if cc == QStyle.CC_ToolButton:
            toolbutton = opt
            if toolbutton:
                button = super().subControlRect(
                    cc, toolbutton, QStyle.SC_ToolButton, widget
                )
                menuarea = super().subControlRect(
                    cc, toolbutton, QStyle.SC_ToolButtonMenu, widget
                )
                bflags = toolbutton.state & ~QStyle.State_Sunken  # type: ignore
                if bflags & QStyle.State_AutoRaise:
                    if not (bflags & QStyle.State_MouseOver) or (
                        not (bflags & QStyle.State_Enabled)
                    ):
                        bflags &= ~QStyle.State_Raised
                mflags = bflags
                if toolbutton.state & QStyle.State_Sunken:  # type: ignore
                    if toolbutton.activeSubControls & QStyle.SC_ToolButton:  # type: ignore
                        bflags |= QStyle.State_Sunken
                    mflags |= QStyle.State_Sunken

                tool = QStyleOption()
                tool.palette = toolbutton.palette
                if toolbutton.subControls & QStyle.SC_ToolButton:  # type: ignore
                    if bflags & (
                        QStyle.State_Sunken | QStyle.State_On | QStyle.State_Raised
                    ):
                        tool.rect = button
                        tool.state = bflags  # type: ignore
                        self.proxy().drawPrimitive(
                            QStyle.PE_PanelButtonTool, tool, p, widget
                        )
                if toolbutton.state & QStyle.State_HasFocus:  # type: ignore
                    fr = QStyleOptionFocusRect(toolbutton)  # type: ignore
                    fr.state = toolbutton.state
                    fr.direction = toolbutton.direction
                    fr.rect = QtCore.QRect(toolbutton.rect)
                    fr.fontMetrics = toolbutton.fontMetrics
                    fr.palette = toolbutton.palette
                    fr.rect.adjust(3, 3, -3, -3)
                    if toolbutton.features & QStyleOptionToolButton.MenuButtonPopup:  # type: ignore

                        fr.rect.adjust(
                            0,
                            0,
                            -self.proxy().pixelMetric(
                                QStyle.PM_MenuButtonIndicator, toolbutton, widget
                            ),
                            0,
                        )
                        self.proxy().drawPrimitive(
                            QStyle.PE_FrameFocusRect, fr, p, widget
                        )
                label = QStyleOptionToolButton(toolbutton)  # type: ignore
                label.state = bflags  # type: ignore
                fw = self.proxy().pixelMetric(QStyle.PM_DefaultFrameWidth, opt, widget)
                label.rect = button.adjusted(fw, fw, -fw, -fw)
                self.proxy().drawControl(QStyle.CE_ToolButtonLabel, label, p, widget)

                if toolbutton.subControls & QStyle.SC_ToolButtonMenu:  # type: ignore
                    tool.rect = menuarea
                    tool.state = mflags  # type: ignore
                    if mflags & (
                        QStyle.State_Sunken | QStyle.State_On | QStyle.State_Raised
                    ):
                        self.proxy().drawPrimitive(
                            QStyle.PE_IndicatorButtonDropDown, tool, p, widget
                        )
                    self.proxy().drawPrimitive(
                        QStyle.PE_IndicatorArrowDown, tool, p, widget
                    )
                elif toolbutton.features & QStyleOptionToolButton.HasMenu:  # type: ignore
                    mbi = self.proxy().pixelMetric(
                        QStyle.PM_MenuButtonIndicator, toolbutton, widget
                    )
                    ir = toolbutton.rect
                    new_toolbutton = toolbutton
                    new_toolbutton.rect = QtCore.QRect(
                        int(ir.center().x() + 1 - (mbi - 6) / 2),
                        ir.y() + ir.height() - mbi + 4,
                        mbi - 6,
                        mbi - 6,
                    )
                    self.proxy().drawPrimitive(
                        QStyle.PE_IndicatorArrowDown, new_toolbutton, p, widget
                    )
            return
        return super(TTToolButtonStyle, self).drawComplexControl(cc, opt, p, widget)