Skip to content

spinbox

ButtonDrawer: custom painting for QPushButton.

SpinBoxDrawer

Source code in client/ayon_core/ui/drawers/spinbox.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class SpinBoxDrawer:
    def __init__(self, style_inst: AYONStyle) -> None:
        self.style_inst = style_inst
        self.model = style_inst.model

    @property
    def _super(self):
        """Return proxy for calling QCommonStyle methods on style_inst."""
        from ..style import AYONStyle as _AYONStyle

        return super(_AYONStyle, self.style_inst)

    @property
    def base_class(self):
        return {"QSpinBox": QSpinBox}

    def register_drawers(self):
        return {
            enum_to_str(
                QStyle.ComplexControl,
                QStyle.ComplexControl.CC_SpinBox,
                "QSpinBox",
            ): self.draw_spinbox,
            enum_to_str(
                QStyle.ComplexControl,
                QStyle.ComplexControl.CC_SpinBox,
                "QSpinBox",
            ): self.draw_spinbox,
        }

    def register_sizers(self):
        return {
            enum_to_str(
                QStyle.ComplexControl,
                QStyle.ComplexControl.CC_SpinBox,
                "QSpinBox",
            ): self.sub_control_rect,
            enum_to_str(
                QStyle.ComplexControl,
                QStyle.ComplexControl.CC_SpinBox,
                "QSpinBox",
            ): self.sub_control_rect,
        }

    def sub_control_rect(
        self,
        cc: QStyle.ComplexControl,
        opt: QStyleOptionSpinBox,
        sc: QStyle.SubControl,
        w: QWidget | None = None,
    ):
        output = self._super.subControlRect(
            cc, opt, sc, w
        )
        if sc in (
            QStyle.SubControl.SC_SpinBoxUp,
            QStyle.SubControl.SC_SpinBoxDown,
        ):
            output.setLeft(output.right() - (output.height() + 1))
        return output

    def draw_spinbox(
        self,
        option: QStyleOption,
        painter: QPainter,
        widget: QWidget | None,
    ) -> None:
        from ayon_core.ui.components import AYSpinBox

        if isinstance(widget, AYSpinBox):
            return

        self._super.drawComplexControl(
            QStyle.ComplexControl.CC_SpinBox, option, painter, widget
        )