Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QStyleOption Class Reference

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

#include <qstyleoption.h>

+ Inheritance diagram for QStyleOption:
+ Collaboration diagram for QStyleOption:

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
}
 This enum is used internally by QStyleOption, its subclasses, and qstyleoption_cast() to determine the type of style option. More...
 
enum  StyleOptionType { Type = SO_Default }
 This enum is used to hold information about the type of the style option, and is defined for each QStyleOption subclass. More...
 
enum  StyleOptionVersion { Version = 1 }
 This enum is used to hold information about the version of the style option, and is defined for each QStyleOption subclass. More...
 

Public Member Functions

 QStyleOption (int version=QStyleOption::Version, int type=SO_Default)
 Constructs a QStyleOption with the specified version and type.
 
 QStyleOption (const QStyleOption &other)
 Constructs a copy of other.
 
 ~QStyleOption ()
 Destroys this style option object.
 
void initFrom (const QWidget *w)
 
QStyleOptionoperator= (const QStyleOption &other)
 Assign other to this QStyleOption.
 

Public Attributes

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

Related Symbols

(Note that these are not member symbols.)

template< typename T > T qstyleoption_cast (const QStyleOption *option)
 \variable QStyleOptionTitleBar::text
 
template< typename T > T qstyleoption_cast (QStyleOption *option)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 

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:

void MyStyle::drawPrimitive(PrimitiveElement element,
const QWidget *widget)
{
if (element == PE_FrameFocusRect) {
qstyleoption_cast<const QStyleOptionFocusRect *>(option);
// ...
}
}
// ...
}

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

See also
QStyle, QStylePainter

Definition at line 38 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 41 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 54 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 55 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 113 of file qstyleoption.cpp.

◆ QStyleOption() [2/2]

QStyleOption::QStyleOption ( const QStyleOption & other)

Constructs a copy of other.

Definition at line 181 of file qstyleoption.cpp.

◆ ~QStyleOption()

QStyleOption::~QStyleOption ( )

Destroys this style option object.

Definition at line 123 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 140 of file qstyleoption.cpp.

References direction, QWidget::fontMetrics(), fontMetrics, QWidget::hasFocus(), QWidget::isEnabled(), QWidget::isWindow(), QWidget::layoutDirection, QWidget::palette, palette, QWidget::rect, rect, QStyleHelper::SizeMini, QStyleHelper::SizeSmall, state, QStyle::State_Active, QStyle::State_Enabled, QStyle::State_HasFocus, QStyle::State_KeyboardFocusChange, QStyle::State_Mini, QStyle::State_MouseOver, QStyle::State_None, QStyle::State_Small, QStyle::State_Window, styleObject, QWidget::underMouse(), Qt::WA_KeyboardFocusChange, widget, QStyleHelper::widgetSizePolicy(), window(), and QWidget::window().

Referenced by QGraphicsLayoutStyleInfo::QGraphicsLayoutStyleInfo(), QLayoutStyleInfo::QLayoutStyleInfo(), QComboBoxPrivateContainer::comboStyleOption(), QMenuPrivate::copyActionToPlatformItem(), QMacStyle::drawControl(), QMenuPrivate::drawScroller(), QMenuPrivate::drawTearOff(), QMenu::event(), QMdi::ControlLabel::event(), QWidgetTextControl::getPaintContext(), QMenuBar::heightForWidth(), QScrollBarPrivate::init(), QTreeViewPrivate::itemDecorationRect(), QWizardPrivate::layoutInfoForCurrentPage(), QTabBarPrivate::layoutTabs(), QCalendarWidget::minimumSizeHint(), QMenuPrivate::mouseEventTaken(), QCalendarPopup::mousePressEvent(), QDateTimeEditPrivate::newHoverControl(), QWidgetPrivate::paintBackground(), QtPrivate::QWellArray::paintCell(), MyPushButton::paintEvent(), QComboBoxPrivateScroller::paintEvent(), QLabel::paintEvent(), QMenu::paintEvent(), QSizeGrip::paintEvent(), QStatusBar::paintEvent(), QTabBar::paintEvent(), QHeaderView::paintEvent(), QListView::paintEvent(), QTipLabel::paintEvent(), QComboBoxListView::paintEvent(), QComboBoxPrivateContainer::paintEvent(), QColumnViewGrip::paintEvent(), QDateTimeEdit::paintEvent(), QDockWidgetTitleButton::paintEvent(), QDockWidget::paintEvent(), QSvgWidget::paintEvent(), QMdiSubWindow::paintEvent(), MyWidget::paintEvent2(), QListViewPrivate::prepareItemsLayout(), QMdi::SimpleCascader::rearrange(), QMenuPrivate::rect(), QTipLabel::resizeEvent(), QComboBoxPrivateContainer::resizeEvent(), QWidgetPrivate::setLayoutItemMargins(), QToolBarExtension::setOrientation(), setStyleSheet(), QLabelPrivate::sizeForWidth(), QMacStyle::sizeFromContents(), QMenu::sizeHint(), QSizeGrip::sizeHint(), QSplitterHandle::sizeHint(), QToolBarExtension::sizeHint(), QMdiSubWindowPrivate::titleBarOptions(), QMenuPrivate::updateActionRects(), and QDateTimeEditPrivate::updateEditFieldGeometry().

+ Here is the call graph for this function:

◆ operator=()

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

Assign other to this QStyleOption.

Definition at line 191 of file qstyleoption.cpp.

References direction, fontMetrics, other(), palette, rect, state, and styleObject.

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ qstyleoption_cast() [1/2]

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

\variable QStyleOptionTitleBar::text

the text of the title bar

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:

void MyStyle::drawPrimitive(PrimitiveElement element,
const QWidget *widget)
{
if (element == PE_FrameFocusRect) {
qstyleoption_cast<const QStyleOptionFocusRect *>(option);
// ...
}
}
// ...
}
See also
QStyleOption::type, QStyleOption::version

Definition at line 665 of file qstyleoption.h.

References opt, SO_Complex, SO_Default, type, and version.

◆ 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 677 of file qstyleoption.h.

References opt, SO_Complex, SO_Default, type, and version.

Member Data Documentation

◆ direction

◆ fontMetrics

◆ palette

◆ rect

QRect QStyleOption::rect

Definition at line 61 of file qstyleoption.h.

Referenced by clonedAnimationStyleOption(), QQC2_NAMESPACE::cocoaControlType(), cocoaControlType(), QItemDelegate::doCheck(), QAndroidStyle::AndroidColorDrawable::draw(), QAndroidStyle::AndroidImageDrawable::draw(), QAndroidStyle::Android9PatchDrawable::draw(), QAndroidStyle::AndroidGradientDrawable::draw(), QTableViewPrivate::drawAndClipSpans(), QTreeView::drawBranches(), QItemDelegate::drawCheck(), QQC2_NAMESPACE::QMacStyle::drawComplexControl(), QQC2::QCommonStyle::drawComplexControl(), QQC2::QWindowsStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QAndroidStyle::drawComplexControl(), QWindows11Style::drawComplexControl(), QWindowsVistaStyle::drawComplexControl(), QAndroidStyle::AndroidControl::drawControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QQC2::QWindowsXPStyle::drawControl(), QWindows11Style::drawControl(), QWindowsVistaStyle::drawControl(), QAndroidStyle::drawControl(), QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QTreeView::drawRow(), QMacStylePrivate::drawToolbarButtonArrow(), if(), if(), initFrom(), QTreeViewPrivate::itemDecorationRect(), QMenuBar::minimumSizeHint(), QTabBarPrivate::normalizedScrollRect(), operator=(), QItemDelegate::paint(), QComboBoxDelegate::paint(), QtPrivate::QWellArray::paintCell(), QQuickStyleItemScrollBar::paintEvent(), QMenu::paintEvent(), QMenuBar::paintEvent(), QSplitterHandle::paintEvent(), QStatusBar::paintEvent(), QTabWidget::paintEvent(), QHeaderView::paintEvent(), QListView::paintEvent(), QToolBar::paintEvent(), QHeaderView::paintSection(), paintSep(), QGraphicsWidget::paintWindowFrame(), QWidgetPrivate::setLayoutItemMargins(), QQC2_NAMESPACE::QMacStyle::sizeFromContents(), QMacStyle::sizeFromContents(), QMenuBar::sizeHint(), QPushButton::sizeHint(), QToolButton::sizeHint(), QComboMenuDelegate::sizeHint(), QQC2::QWindowsStyle::styleHint(), QMacStyle::styleHint(), QQC2_NAMESPACE::QMacStyle::styleHint(), QCommonStyle::styleHint(), QQC2::QCommonStyle::styleHint(), QQC2_NAMESPACE::QMacStyle::subControlRect(), QQC2::QCommonStyle::subControlRect(), QMacStyle::subControlRect(), QCommonStyle::subControlRect(), QAndroidStyle::subControlRect(), QQC2_NAMESPACE::QMacStyle::subElementRect(), QQC2::QCommonStyle::subElementRect(), QQC2::QWindowsStyle::subElementRect(), QMacStyle::subElementRect(), QCommonStyle::subElementRect(), QQC2::QMacStylePrivate::tabLayout(), QQC2::QCommonStylePrivate::tabLayout(), QMdiSubWindowPrivate::titleBarHeight(), QMdiSubWindowPrivate::titleBarOptions(), QMdiSubWindowPrivate::updateMask(), QFocusFramePrivate::updateSize(), QFramePrivate::updateStyledFrameWidths(), QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(), and QGraphicsWidgetPrivate::windowFrameMouseReleaseEvent().

◆ state

QStyle::State QStyleOption::state

Definition at line 59 of file qstyleoption.h.

Referenced by QGraphicsLayoutStyleInfo::QGraphicsLayoutStyleInfo(), QStyleOptionFocusRect::QStyleOptionFocusRect(), QStyleOptionProgressBar::QStyleOptionProgressBar(), QAndroidStyle::AndroidStateDrawable::bestAndroidStateMatch(), QTreeView::drawBranches(), QTableViewPrivate::drawCell(), QItemDelegate::drawCheck(), QQC2_NAMESPACE::QMacStyle::drawComplexControl(), QQC2::QCommonStyle::drawComplexControl(), QQC2::QWindowsStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QWindowsVistaStyle::drawComplexControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QWindows11Style::drawControl(), QWindowsVistaStyle::drawControl(), QWindowsVistaStyle::drawPrimitive(), QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QTreeView::drawRow(), QTabWidget::heightForWidth(), QMenuBar::heightForWidth(), if(), if(), if(), initFrom(), QHeaderView::initStyleOptionForIndex(), QMenuBar::minimumSizeHint(), QTabWidget::minimumSizeHint(), operator=(), QCompleterItemDelegate::paint(), QtPrivate::QWellArray::paintCell(), QtPrivate::QPrevNextCalButton::paintEvent(), QScrollBar::paintEvent(), QSplitterHandle::paintEvent(), QStatusBar::paintEvent(), QHeaderView::paintEvent(), QtPrivate::QCalToolButton::paintEvent(), QDateTimeEdit::paintEvent(), QDockWidgetTitleButton::paintEvent(), QMdi::ControllerWidget::paintEvent(), paintSep(), QGraphicsWidget::paintWindowFrame(), QQC2::QCommonStyle::pixelMetric(), QCommonStyle::pixelMetric(), QQC2_NAMESPACE::QMacStyle::pixelMetric(), QMacStyle::pixelMetric(), QQC2_NAMESPACE::QMacStyle::sizeFromContents(), QMenuBar::sizeHint(), QProgressBar::sizeHint(), QSplitterHandle::sizeHint(), QTabWidget::sizeHint(), QQC2_NAMESPACE::QMacStyle::subElementRect(), QQC2::QCommonStyle::subElementRect(), QMacStyle::subElementRect(), QCommonStyle::subElementRect(), QQC2::QMacStylePrivate::tabLayout(), QQC2::QCommonStylePrivate::tabLayout(), QMdiSubWindowPrivate::titleBarOptions(), QQC2::QStyleHelper::widgetSizePolicy(), and QStyleHelper::widgetSizePolicy().

◆ styleObject

◆ type

int QStyleOption::type

◆ version

int QStyleOption::version

Definition at line 57 of file qstyleoption.h.

Referenced by qstyleoption_cast(), and qstyleoption_cast().


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