Table Of Contents

Previous topic


Next topic



Inherited by: QStyleOptionToolBox, QStyleOptionToolBoxV2, QStyleOptionTabBarBase, QStyleOptionTabBarBaseV2, QStyleOptionTabWidgetFrame, QStyleOptionViewItem, QStyleOptionViewItemV2, QStyleOptionViewItemV3, QStyleOptionViewItemV4, QStyleOptionFrame, QStyleOptionFrameV2, QStyleOptionFrameV3, QStyleOptionFocusRect, QStyleOptionGraphicsItem, QStyleOptionDockWidget, QStyleOptionDockWidgetV2, QStyleOptionMenuItem, QStyleOptionProgressBar, QStyleOptionProgressBarV2, QStyleOptionToolBar, QStyleOptionTab, QStyleOptionTabV2, QStyleOptionTabV3, QStyleOptionComplex, QStyleOptionSizeGrip, QStyleOptionGroupBox, QStyleOptionTitleBar, QStyleOptionComboBox, QStyleOptionToolButton, QStyleOptionSpinBox, QStyleOptionSlider, QStyleOptionButton, QStyleOptionRubberBand, QStyleOptionHeader



Detailed Description

The PySide.QtGui.QStyleOption class stores the parameters used by PySide.QtGui.QStyle functions.

PySide.QtGui.QStyleOption and its subclasses contain all the information that PySide.QtGui.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 low-level feel makes the structures straightforward to use and emphasizes that these are simply parameters used by the style functions.

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

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

def paintEvent(self, qpaintevent):
    option = QStyleOptionButton()
    if isDown():
        option.state = QStyle.State_Sunken
        option.state = QStyle.State_Raised

    if self.isDefault():
        option.features = option.features or QStyleOptionButton.DefaultButton
    option.text = self.text()
    option.icon = self.icon()

    painter = QPainter(self), option, painter, self)

In our example, the control is a QStyle.CE_PushButton , and according to the QStyle.drawControl() documentation the corresponding class is PySide.QtGui.QStyleOptionButton .

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

def drawPrimitive(self, element, option, painter, widget):
    if element == self.PE_FrameFocusRect:
        focusRectOption =  QStyleOptionFocusRect(option)
        if focusRectOption:
            # ...

    # ...

The qstyleoption_cast() 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 PySide.QtGui.QStyleOption(other)
class PySide.QtGui.QStyleOption([version=QStyleOption.Version[, type=SO_Default]])

Constructs a copy of other .

Constructs a PySide.QtGui.QStyleOption with the specified version and type .

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

The state member variable is initialized to QStyle.State_None .

See also

version type


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

Constant Description
QStyleOption.Version 1

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

See also



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

Constant Description
QStyleOption.Type The type of style option provided ( SO_Default for this class).

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

See also



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

Constant Description
QStyleOption.SO_Button PySide.QtGui.QStyleOptionButton
QStyleOption.SO_ComboBox PySide.QtGui.QStyleOptionComboBox
QStyleOption.SO_Complex PySide.QtGui.QStyleOptionComplex
QStyleOption.SO_Default PySide.QtGui.QStyleOption
QStyleOption.SO_DockWidget PySide.QtGui.QStyleOptionDockWidget
QStyleOption.SO_FocusRect PySide.QtGui.QStyleOptionFocusRect
QStyleOption.SO_Frame PySide.QtGui.QStyleOptionFrame PySide.QtGui.QStyleOptionFrameV2
QStyleOption.SO_GraphicsItem PySide.QtGui.QStyleOptionGraphicsItem
QStyleOption.SO_GroupBox PySide.QtGui.QStyleOptionGroupBox
QStyleOption.SO_Header PySide.QtGui.QStyleOptionHeader
QStyleOption.SO_MenuItem PySide.QtGui.QStyleOptionMenuItem
QStyleOption.SO_ProgressBar PySide.QtGui.QStyleOptionProgressBar PySide.QtGui.QStyleOptionProgressBarV2
QStyleOption.SO_RubberBand PySide.QtGui.QStyleOptionRubberBand
QStyleOption.SO_SizeGrip PySide.QtGui.QStyleOptionSizeGrip
QStyleOption.SO_Slider PySide.QtGui.QStyleOptionSlider
QStyleOption.SO_SpinBox PySide.QtGui.QStyleOptionSpinBox
QStyleOption.SO_Tab PySide.QtGui.QStyleOptionTab
QStyleOption.SO_TabBarBase PySide.QtGui.QStyleOptionTabBarBase
QStyleOption.SO_TabWidgetFrame PySide.QtGui.QStyleOptionTabWidgetFrame
QStyleOption.SO_TitleBar PySide.QtGui.QStyleOptionTitleBar
QStyleOption.SO_ToolBar PySide.QtGui.QStyleOptionToolBar
QStyleOption.SO_ToolBox PySide.QtGui.QStyleOptionToolBox
QStyleOption.SO_ToolButton PySide.QtGui.QStyleOptionToolButton
QStyleOption.SO_ViewItem PySide.QtGui.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

Some style options are defined for various Qt3Support controls:

Constant Description
QStyleOption.SO_Q3DockWindow QStyleOptionQ3DockWindow
QStyleOption.SO_Q3ListView QStyleOptionQ3ListView
QStyleOption.SO_Q3ListViewItem QStyleOptionQ3ListViewItem

See also



Initializes the state , direction , rect , palette , and fontMetrics member variables based on the specified widget .

This is a convenience function; the member variables can also be initialized manually.