![]() |
CopperSpice API
1.7.4
|
The QStyleOption class stores the parameters used by QStyle functions. More...
Public Types | |
enum | OptionType |
enum | StyleOptionType |
enum | StyleOptionVersion |
Public Methods | |
QStyleOption (const QStyleOption &other) | |
QStyleOption (int version=QStyleOption::Version, int type=SO_Default) | |
~QStyleOption () | |
void | initFrom (const QWidget *widget) |
QStyleOption & | operator= (const QStyleOption &other) |
Related Functions | |
These are not member functions | |
T | qstyleoption_cast (const QStyleOption *option) |
T | qstyleoption_cast (QStyleOption *option) |
The QStyleOption class stores the parameters used by QStyle functions. 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 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 QStyle function usually creates QStyleOption objects on the stack. This combined with the CopperSpice 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:
In our example, the control is a QStyle::CE_PushButton, and according to the QStyle::drawControl() 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 qstyleoption_cast() to ensure that the pointer type is correct.
The qstyleoption_cast() function will return nullptr if the object to which option
points is not of the correct type.
This enum is used internally by QStyleOption and its subclasses
Constant | Value | Description |
---|---|---|
QStyleOption::SO_Button | 2 | QStyleOptionButton |
QStyleOption::SO_ComboBox | ? | QStyleOptionComboBox |
QStyleOption::SO_Complex | 0xf0000 | QStyleOptionComplex |
QStyleOption::SO_Default | 0 | QStyleOption |
QStyleOption::SO_DockWidget | 9 | QStyleOptionDockWidget |
QStyleOption::SO_FocusRect | 1 | QStyleOptionFocusRect |
QStyleOption::SO_Frame | 5 | QStyleOptionFrame |
QStyleOption::SO_GraphicsItem | 15 | QStyleOptionGraphicsItem |
QStyleOption::SO_GroupBox | ? | QStyleOptionGroupBox |
QStyleOption::SO_Header | 8 | QStyleOptionHeader |
QStyleOption::SO_MenuItem | 4 | QStyleOptionMenuItem |
QStyleOption::SO_ProgressBar | 6 | QStyleOptionProgressBar |
QStyleOption::SO_RubberBand | 13 | QStyleOptionRubberBand |
QStyleOption::SO_SizeGrip | ? | QStyleOptionSizeGrip |
QStyleOption::SO_Slider | ? | QStyleOptionSlider |
QStyleOption::SO_SpinBox | ? | QStyleOptionSpinBox |
QStyleOption::SO_Tab | 3 | QStyleOptionTab |
QStyleOption::SO_TabBarBase | 12 | QStyleOptionTabBarBase |
QStyleOption::SO_TabWidgetFrame | 11 | QStyleOptionTabWidgetFrame |
QStyleOption::SO_TitleBar | ? | QStyleOptionTitleBar |
QStyleOption::SO_ToolBar | 14 | QStyleOptionToolBar |
QStyleOption::SO_ToolBox | 7 | QStyleOptionToolBox |
QStyleOption::SO_ToolButton | ? | QStyleOptionToolButton |
QStyleOption::SO_ViewItem | 10 | QStyleOptionViewItem (used in Interviews) |
The following values are used for custom controls:
Constant | Value | Description |
---|---|---|
QStyleOption::SO_CustomBase | 0xf00 | Reserved for custom QStyleOptions; all custom controls values must be above this value |
QStyleOption::SO_ComplexCustomBase | 0xf000000 | Reserved for custom QStyleOptions; all custom complex controls values must be above this value |
This enum is used to hold information about the type of the style option and is defined for each QStyleOption subclass.
Constant | Value | Description |
---|---|---|
QStyleOption::Type | SO_Default | The type of style option provided (SO_Default for this class). |
This enum is used to hold information about the version of the style option, and is defined for each QStyleOption subclass.
Constant | Value | Description |
---|---|---|
QStyleOption::Version | 1 | 1 |
QStyleOption::QStyleOption | ( | int | version = QStyleOption::Version , |
int | type = SO_Default |
||
) |
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 QStyle::State_None.
QStyleOption::QStyleOption | ( | const QStyleOption & | other | ) |
Constructs a copy of other.
QStyleOption::~QStyleOption | ( | ) |
Destroys this style option object.
void QStyleOption::initFrom | ( | const QWidget * | widget | ) |
Initializes the state, direction, rect, palette, and fontMetrics member variables based on the specified widget.
QStyleOption & QStyleOption::operator= | ( | const QStyleOption & | other | ) |
Assign other to this QStyleOption.
|
related |
Returns a T or 0 depending on the type and version of the given option.
|
related |
Returns a T or 0 depending on the type of the given option.