QtBase  v6.3.1
Public Types | Public Member Functions | Public Attributes | Related Functions | List of all members
QStyleOption Class Reference

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

#include <qstyleoption.h>

Inheritance diagram for QStyleOption:
Inheritance graph
[legend]
Collaboration diagram for QStyleOption:
Collaboration graph
[legend]

Public Types

enum  OptionType {
  SO_Default , SO_FocusRect , SO_Button , SO_Tab ,
  SO_MenuItem , SO_Frame , SO_ProgressBar , SO_ToolBox ,
  SO_Header , SO_DockWidget , SO_ViewItem , SO_TabWidgetFrame ,
  SO_TabBarBase , SO_RubberBand , SO_ToolBar , SO_GraphicsItem ,
  SO_Complex = 0xf0000 , SO_Slider , SO_SpinBox , SO_ToolButton ,
  SO_ComboBox , SO_TitleBar , SO_GroupBox , SO_SizeGrip ,
  SO_CustomBase = 0xf00 , SO_ComplexCustomBase = 0xf000000
}
 
enum  StyleOptionType { Type = SO_Default }
 
enum  StyleOptionVersion { Version = 1 }
 

Public Member Functions

 QStyleOption (int version=QStyleOption::Version, int type=SO_Default)
 
 QStyleOption (const QStyleOption &other)
 
 ~QStyleOption ()
 
void initFrom (const QWidget *w)
 
QStyleOptionoperator= (const QStyleOption &other)
 

Public Attributes

int version
 
int type
 
QStyle::State state
 
Qt::LayoutDirection direction
 
QRect rect
 
QFontMetrics fontMetrics
 
QPalette palette
 
QObjectstyleObject
 

Related Functions

(Note that these are not member functions.)

template< typename T > T qstyleoption_cast (const QStyleOption *option)
 the text of the title bar More...
 
template< typename T > T qstyleoption_cast (QStyleOption *option)
 

Detailed Description

The QStyleOption class stores the parameters used by QStyle functions.

\inmodule QtWidgets

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 \l{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. For example:

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 \l {widgets/styles}{Styles} example.

See also
QStyle, QStylePainter

Definition at line 74 of file qstyleoption.h.

Member Enumeration Documentation

◆ OptionType

This enum is used internally by 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 QStyleOption subclass and your own styles.

\value SO_Button \l QStyleOptionButton \value SO_ComboBox \l QStyleOptionComboBox \value SO_Complex \l QStyleOptionComplex \value SO_Default QStyleOption \value SO_DockWidget \l QStyleOptionDockWidget \value SO_FocusRect \l QStyleOptionFocusRect \value SO_Frame \l QStyleOptionFrame \value SO_GraphicsItem \l QStyleOptionGraphicsItem \value SO_GroupBox \l QStyleOptionGroupBox \value SO_Header \l QStyleOptionHeader \value SO_MenuItem \l QStyleOptionMenuItem \value SO_ProgressBar \l QStyleOptionProgressBar \value SO_RubberBand \l QStyleOptionRubberBand \value SO_SizeGrip \l QStyleOptionSizeGrip \value SO_Slider \l QStyleOptionSlider \value SO_SpinBox \l QStyleOptionSpinBox \value SO_Tab \l QStyleOptionTab \value SO_TabBarBase \l QStyleOptionTabBarBase \value SO_TabWidgetFrame \l QStyleOptionTabWidgetFrame \value SO_TitleBar \l QStyleOptionTitleBar \value SO_ToolBar \l QStyleOptionToolBar \value SO_ToolBox \l QStyleOptionToolBox \value SO_ToolButton \l QStyleOptionToolButton \value SO_ViewItem \l QStyleOptionViewItem (used in Interviews)

The following values are used for custom controls:

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

See also
type
Enumerator
SO_Default 
SO_FocusRect 
SO_Button 
SO_Tab 
SO_MenuItem 
SO_Frame 
SO_ProgressBar 
SO_ToolBox 
SO_Header 
SO_DockWidget 
SO_ViewItem 
SO_TabWidgetFrame 
SO_TabBarBase 
SO_RubberBand 
SO_ToolBar 
SO_GraphicsItem 
SO_Complex 
SO_Slider 
SO_SpinBox 
SO_ToolButton 
SO_ComboBox 
SO_TitleBar 
SO_GroupBox 
SO_SizeGrip 
SO_CustomBase 
SO_ComplexCustomBase 

Definition at line 77 of file qstyleoption.h.

◆ StyleOptionType

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

\value Type The type of style option provided (\l{SO_Default} for this class).

The type is used internally by 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 QStyleOption subclass and your own styles.

See also
StyleOptionVersion
Enumerator
Type 

Definition at line 90 of file qstyleoption.h.

◆ StyleOptionVersion

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

\value Version 1

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

See also
StyleOptionType
Enumerator
Version 

Definition at line 91 of file qstyleoption.h.

Constructor & Destructor Documentation

◆ QStyleOption() [1/2]

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 \l state member variable is initialized to QStyle::State_None.

See also
version, type

Definition at line 152 of file qstyleoption.cpp.

◆ QStyleOption() [2/2]

QStyleOption::QStyleOption ( const QStyleOption other)

Constructs a copy of other.

Definition at line 220 of file qstyleoption.cpp.

◆ ~QStyleOption()

QStyleOption::~QStyleOption ( )

Destroys this style option object.

Definition at line 162 of file qstyleoption.cpp.

Member Function Documentation

◆ initFrom()

void QStyleOption::initFrom ( const QWidget widget)
Since
4.1

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

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

See also
QWidget::layoutDirection(), QWidget::rect(), QWidget::palette(), QWidget::fontMetrics()

Definition at line 179 of file qstyleoption.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

QStyleOption & QStyleOption::operator= ( const QStyleOption other)

Assign other to this QStyleOption.

Definition at line 230 of file qstyleoption.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ qstyleoption_cast() [1/2]

template< typename T > T qstyleoption_cast< T > ( const QStyleOption option)
related

the text of the title bar

\variable QStyleOptionTitleBar::text

The default value is an empty string.

\variable QStyleOptionTitleBar::icon

the icon for the title bar

The default value is an empty icon, i.e. an icon with neither a pixmap nor a filename.

\variable QStyleOptionTitleBar::titleBarState

the state of the title bar

This is basically the window state of the underlying widget. The default value is 0.

See also
QWidget::windowState()

\variable QStyleOptionTitleBar::titleBarFlags

the widget flags for the title bar

The default value is Qt::Widget.

See also
Qt::WindowFlags

Returns a T or \nullptr depending on the \l{QStyleOption::type}{type} and \l{QStyleOption::version}{version} of the given option.

Example:

See also
QStyleOption::type, QStyleOption::version

Definition at line 700 of file qstyleoption.h.

◆ qstyleoption_cast() [2/2]

template< typename T > T qstyleoption_cast< T > ( QStyleOption option)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a T or \nullptr depending on the type of the given option.

Definition at line 712 of file qstyleoption.h.

Member Data Documentation

◆ direction

Qt::LayoutDirection QStyleOption::direction

Definition at line 96 of file qstyleoption.h.

◆ fontMetrics

QFontMetrics QStyleOption::fontMetrics

Definition at line 98 of file qstyleoption.h.

◆ palette

QPalette QStyleOption::palette

Definition at line 99 of file qstyleoption.h.

◆ rect

QRect QStyleOption::rect

Definition at line 97 of file qstyleoption.h.

◆ state

QStyle::State QStyleOption::state

Definition at line 95 of file qstyleoption.h.

◆ styleObject

QObject* QStyleOption::styleObject

Definition at line 100 of file qstyleoption.h.

◆ type

int QStyleOption::type

Definition at line 94 of file qstyleoption.h.

◆ version

int QStyleOption::version

Definition at line 93 of file qstyleoption.h.


The documentation for this class was generated from the following files: