QStyleOption

The QStyleOption class stores the parameters used by QStyle functions. More

Inheritance diagram of PySide6.QtWidgets.QStyleOption

Inherited by: QStyleOptionViewItem, QStyleOptionToolBox, QStyleOptionToolBar, QStyleOptionTabWidgetFrame, QStyleOptionTabBarBase, QStyleOptionTab, QStyleOptionRubberBand, QStyleOptionProgressBar, QStyleOptionMenuItem, QStyleOptionHeader, QStyleOptionHeaderV2, QStyleOptionGraphicsItem, QStyleOptionFrame, QStyleOptionFocusRect, QStyleOptionDockWidget, QStyleOptionComplex, QStyleOptionToolButton, QStyleOptionTitleBar, QStyleOptionSpinBox, QStyleOptionSlider, QStyleOptionSizeGrip, QStyleOptionGroupBox, QStyleOptionComboBox, QStyleOptionButton

Synopsis

Functions

Detailed Description

QStyleOption and its subclasses contain all the information that QStyle functions need to draw a graphical element.

For performance reasons, there are few member functions and the access to the member variables is direct (i.e., using the . or -> operator). This makes the structures straightforward to use and emphasizes that these are simply parameters used by the style functions.

The caller of a QStyle function usually creates QStyleOption objects on the stack. This combined with Qt’s extensive use of implicit sharing for types such as QString , QPalette , and QColor ensures that no memory allocation needlessly takes place.

The following code snippet shows how to use a specific QStyleOption subclass to paint a push button:

def paintEvent(self, arg__0):

    option = QStyleOptionButton()
    option.initFrom(self)
    option.state = isDown() if QStyle.State_Sunken else QStyle.State_Raised
    if isDefault():
        option.features |= QStyleOptionButton.DefaultButton
    option.text = text()
    option.icon = icon()
    painter = QPainter(self)
    style().drawControl(QStyle.CE_PushButton, option, painter, self)

In our example, the control is a CE_PushButton , and according to the documentation the corresponding class is QStyleOptionButton .

When reimplementing QStyle functions that take a QStyleOption parameter, you often need to cast the QStyleOption to a subclass. For safety, you can use to ensure that the pointer type is correct. For example:

def drawPrimitive(self, element,):
                            option, = QStyleOption()
                            painter, = QPainter()
                            widget) = QWidget()

    if element == PE_FrameFocusRect:
        focusRectOption =
                qstyleoption_cast<QStyleOptionFocusRect *>(option)
        if focusRectOption:
            # ...


    # ...

The function will return 0 if the object to which option points is not of the correct type.

For an example demonstrating how style options can be used, see the Styles example.

class PySide6.QtWidgets.QStyleOption(other)

PySide6.QtWidgets.QStyleOption([version=QStyleOption.Version[, type=SO_Default]])

Parameters

Constructs a copy of other.

Constructs a QStyleOption with the specified version and type.

The version has no special meaning for QStyleOption ; it can be used by subclasses to distinguish between different version of the same option type.

The state member variable is initialized to State_None .

See also

version type

PySide6.QtWidgets.QStyleOption.OptionType

This enum is used internally by QStyleOption , its subclasses, and to determine the type of style option. In general you do not need to worry about this unless you want to create your own QStyleOption subclass and your own styles.

Constant

Description

QStyleOption.SO_Button

QStyleOptionButton

QStyleOption.SO_ComboBox

QStyleOptionComboBox

QStyleOption.SO_Complex

QStyleOptionComplex

QStyleOption.SO_Default

QStyleOption

QStyleOption.SO_DockWidget

QStyleOptionDockWidget

QStyleOption.SO_FocusRect

QStyleOptionFocusRect

QStyleOption.SO_Frame

QStyleOptionFrame

QStyleOption.SO_GraphicsItem

QStyleOptionGraphicsItem

QStyleOption.SO_GroupBox

QStyleOptionGroupBox

QStyleOption.SO_Header

QStyleOptionHeader

QStyleOption.SO_MenuItem

QStyleOptionMenuItem

QStyleOption.SO_ProgressBar

QStyleOptionProgressBar

QStyleOption.SO_RubberBand

QStyleOptionRubberBand

QStyleOption.SO_SizeGrip

QStyleOptionSizeGrip

QStyleOption.SO_Slider

QStyleOptionSlider

QStyleOption.SO_SpinBox

QStyleOptionSpinBox

QStyleOption.SO_Tab

QStyleOptionTab

QStyleOption.SO_TabBarBase

QStyleOptionTabBarBase

QStyleOption.SO_TabWidgetFrame

QStyleOptionTabWidgetFrame

QStyleOption.SO_TitleBar

QStyleOptionTitleBar

QStyleOption.SO_ToolBar

QStyleOptionToolBar

QStyleOption.SO_ToolBox

QStyleOptionToolBox

QStyleOption.SO_ToolButton

QStyleOptionToolButton

QStyleOption.SO_ViewItem

QStyleOptionViewItem (used in Interviews)

The following values are used for custom controls:

Constant

Description

QStyleOption.SO_CustomBase

Reserved for custom QStyleOptions; all custom controls values must be above this value

QStyleOption.SO_ComplexCustomBase

Reserved for custom QStyleOptions; all custom complex controls values must be above this value

See also

type

PySide6.QtWidgets.QStyleOption.StyleOptionType

This enum is used to hold information about the type of the style option, and is defined for each QStyleOption subclass.

Constant

Description

QStyleOption.Type

The type of style option provided ( SO_Default for this class).

The type is used internally by QStyleOption , its subclasses, and to determine the type of style option. In general you do not need to worry about this unless you want to create your own QStyleOption subclass and your own styles.

See also

StyleOptionVersion

PySide6.QtWidgets.QStyleOption.StyleOptionVersion

This enum is used to hold information about the version of the style option, and is defined for each QStyleOption subclass.

Constant

Description

QStyleOption.Version

1

The version is used by QStyleOption subclasses to implement extensions without breaking compatibility. If you use , you normally do not need to check it.

See also

StyleOptionType

PySide6.QtWidgets.QStyleOption.version
PySide6.QtWidgets.QStyleOption.type
PySide6.QtWidgets.QStyleOption.state
PySide6.QtWidgets.QStyleOption.direction
PySide6.QtWidgets.QStyleOption.rect
PySide6.QtWidgets.QStyleOption.fontMetrics
PySide6.QtWidgets.QStyleOption.palette
PySide6.QtWidgets.QStyleOption.styleObject
PySide6.QtWidgets.QStyleOption.initFrom(w)
Parameters

wPySide6.QtWidgets.QWidget