- class QStyleOption#
The
QStyleOption
class stores the parameters used byQStyle
functions. More…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#
Methods#
def
__init__()
def
initFrom()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
QStyleOption
and its subclasses contain all the information thatQStyle
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 createsQStyleOption
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 thedrawControl()
documentation the corresponding class isQStyleOptionButton
.When reimplementing
QStyle
functions that take aQStyleOption
parameter, you often need to cast theQStyleOption
to a subclass. For safety, you can useqstyleoption_cast()
to ensure that the pointer type is correct. For example:def drawPrimitive(self, element,): QStyleOption option, QPainter painter, QWidget widget) if element == PE_FrameFocusRect: focusRectOption = QStyleOptionFocusRect(option) if focusRectOption: # ... # ...
The
qstyleoption_cast()
function will return 0 if the object to whichoption
points is not of the correct type.See also
- class OptionType#
This enum is used internally by
QStyleOption
, its subclasses, andqstyleoption_cast()
to determine the type of style option. In general you do not need to worry about this unless you want to create your ownQStyleOption
subclass and your own styles.Constant
Description
QStyleOption.SO_Button
QStyleOption.SO_ComboBox
QStyleOption.SO_Complex
QStyleOption.SO_Default
QStyleOption.SO_DockWidget
QStyleOption.SO_FocusRect
QStyleOption.SO_Frame
QStyleOption.SO_GraphicsItem
QStyleOption.SO_GroupBox
QStyleOption.SO_Header
QStyleOption.SO_MenuItem
QStyleOption.SO_ProgressBar
QStyleOption.SO_RubberBand
QStyleOption.SO_SizeGrip
QStyleOption.SO_Slider
QStyleOption.SO_SpinBox
QStyleOption.SO_Tab
QStyleOption.SO_TabBarBase
QStyleOption.SO_TabWidgetFrame
QStyleOption.SO_TitleBar
QStyleOption.SO_ToolBar
QStyleOption.SO_ToolBox
QStyleOption.SO_ToolButton
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
- class 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, andqstyleoption_cast()
to determine the type of style option. In general you do not need to worry about this unless you want to create your ownQStyleOption
subclass and your own styles.See also
- class 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 useqstyleoption_cast()
, you normally do not need to check it.See also
- 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#
- __init__(other)#
- Parameters:
other –
QStyleOption
Constructs a copy of
other
.- __init__([version=QStyleOption.StyleOptionVersion.Version[, type=QStyleOption.OptionType.SO_Default]])
- Parameters:
version – int
type – int
Constructs a
QStyleOption
with the specifiedversion
andtype
.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
.Initializes the state , direction , rect , palette , fontMetrics and styleObject member variables based on the specified
widget
.This is a convenience function; the member variables can also be initialized manually.
See also