![]() |
Qt 6.x
The Qt SDK
|
The QStyleOption class stores the parameters used by QStyle functions. More...
#include <qstyleoption.h>
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) |
QStyleOption & | operator= (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 |
QObject * | styleObject |
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. | |
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.
Definition at line 38 of file qstyleoption.h.
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
Definition at line 41 of file qstyleoption.h.
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.
Enumerator | |
---|---|
Type |
Definition at line 54 of file qstyleoption.h.
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.
Enumerator | |
---|---|
Version |
Definition at line 55 of file qstyleoption.h.
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.
Definition at line 113 of file qstyleoption.cpp.
QStyleOption::QStyleOption | ( | const QStyleOption & | other | ) |
Constructs a copy of other.
Definition at line 181 of file qstyleoption.cpp.
QStyleOption::~QStyleOption | ( | ) |
Destroys this style option object.
Definition at line 123 of file qstyleoption.cpp.
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.
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(), QMdi::ControlLabel::event(), QWidgetTextControl::getPaintContext(), QMenuBar::heightForWidth(), QScrollBarPrivate::init(), QTreeViewPrivate::itemDecorationRect(), QTabBarPrivate::layoutTabs(), QMenuPrivate::mouseEventTaken(), QCalendarPopup::mousePressEvent(), QDateTimeEditPrivate::newHoverControl(), QWidgetPrivate::paintBackground(), QtPrivate::QWellArray::paintCell(), 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(), QMdi::SimpleCascader::rearrange(), QMenuPrivate::rect(), 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().
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.
|
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.
\variable QStyleOptionTitleBar::titleBarFlags
the widget flags for the title bar
The default value is Qt::Widget.
Returns a T or \nullptr depending on the \l{QStyleOption::type}{type} and \l{QStyleOption::version}{version} of the given option.
Example:
Definition at line 665 of file qstyleoption.h.
References opt, SO_Complex, SO_Default, type, and version.
|
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.
Qt::LayoutDirection QStyleOption::direction |
Definition at line 60 of file qstyleoption.h.
Referenced by QCommonStyle::drawComplexControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), if(), initFrom(), operator=(), QCommonStyle::styleHint(), QQC2::QCommonStyle::styleHint(), QAndroidStyle::subControlRect(), QQC2_NAMESPACE::QMacStyle::subElementRect(), QQC2::QCommonStyle::subElementRect(), QQC2::QWindowsStyle::subElementRect(), QMacStyle::subElementRect(), QCommonStyle::subElementRect(), QQC2::QMacStylePrivate::tabLayout(), QQC2::QCommonStylePrivate::tabLayout(), and QQC2::QCommonStylePrivate::viewItemLayout().
QFontMetrics QStyleOption::fontMetrics |
Definition at line 62 of file qstyleoption.h.
Referenced by QQC2_NAMESPACE::QMacStyle::drawControl(), QMacStyle::drawControl(), QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QMacStyle::drawPrimitive(), initFrom(), QHeaderView::initStyleOptionForIndex(), operator=(), QFileDialogComboBox::paintEvent(), QDockWidget::paintEvent(), QQC2::QCommonStyle::pixelMetric(), QCommonStyle::pixelMetric(), qt_aqua_get_known_size(), QHeaderView::sectionSizeFromContents(), QItemDelegate::setOptions(), QAndroidStyle::AndroidControl::sizeFromContents(), QQC2_NAMESPACE::QMacStyle::sizeFromContents(), QAndroidStyle::sizeFromContents(), QMacStyle::sizeFromContents(), QAndroidStyle::subControlRect(), QQC2::QCommonStyle::subElementRect(), QCommonStyle::subElementRect(), QQC2::QMacStylePrivate::tabLayout(), QMdiSubWindowPrivate::titleBarOptions(), QMenuPrivate::updateActionRects(), and QQC2::QCommonStylePrivate::viewItemLayout().
QPalette QStyleOption::palette |
Definition at line 63 of file qstyleoption.h.
Referenced by QApplicationPrivate::applyQIconStyleHelper(), QTableViewPrivate::drawCell(), QQC2_NAMESPACE::QMacStyle::drawComplexControl(), QQC2::QCommonStyle::drawComplexControl(), QQC2::QWindowsStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QAndroidStyle::AndroidControl::drawControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QTreeView::drawRow(), QCommonStyle::generatedIconPixmap(), QQC2::QCommonStyle::generatedIconPixmap(), QWidgetTextControl::getPaintContext(), if(), initFrom(), QHeaderView::initStyleOptionForIndex(), QMenuBar::minimumSizeHint(), QTabWidget::minimumSizeHint(), operator=(), QComboMenuDelegate::paint(), QtPrivate::QWellArray::paintCell(), QLabel::paintEvent(), QMenuBar::paintEvent(), QSplitterHandle::paintEvent(), QStatusBar::paintEvent(), QComboBox::paintEvent(), QComboBoxListView::paintEvent(), QHeaderView::paintSection(), paintSep(), QGraphicsWidget::paintWindowFrame(), QItemDelegate::setOptions(), QMenuBar::sizeHint(), QCommonStyle::styleHint(), QQC2::QCommonStyle::styleHint(), and QMdiSubWindowPrivate::titleBarOptions().
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(), QWindowsVistaStyle::drawComplexControl(), QAndroidStyle::AndroidControl::drawControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QQC2::QWindowsXPStyle::drawControl(), QWindowsVistaStyle::drawControl(), QAndroidStyle::drawControl(), QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QTreeView::drawRow(), QMenuPrivate::drawScroller(), QMenuPrivate::drawTearOff(), 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(), QQC2::QCommonStylePrivate::viewItemLayout(), QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(), and QGraphicsWidgetPrivate::windowFrameMouseReleaseEvent().
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(), QWindowsVistaStyle::drawControl(), QWindowsVistaStyle::drawPrimitive(), QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QTreeView::drawRow(), QMenuPrivate::drawScroller(), QMenuPrivate::drawTearOff(), QTabWidget::heightForWidth(), QMenuBar::heightForWidth(), if(), if(), if(), initFrom(), QHeaderView::initStyleOptionForIndex(), QMenuBar::minimumSizeHint(), QTabWidget::minimumSizeHint(), operator=(), QCompleterItemDelegate::paint(), QtPrivate::QWellArray::paintCell(), QtPrivate::QPrevNextCalButton::paintEvent(), QComboBoxPrivateScroller::paintEvent(), QMenu::paintEvent(), QMenuBar::paintEvent(), QScrollBar::paintEvent(), QSplitterHandle::paintEvent(), QStatusBar::paintEvent(), QHeaderView::paintEvent(), QtPrivate::QCalToolButton::paintEvent(), QComboBoxListView::paintEvent(), QDateTimeEdit::paintEvent(), QDockWidgetTitleButton::paintEvent(), QMdi::ControllerWidget::paintEvent(), QMdiSubWindow::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().
QObject* QStyleOption::styleObject |
Definition at line 64 of file qstyleoption.h.
Referenced by QQC2_NAMESPACE::QMacStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QWindowsVistaStyle::drawPrimitive(), QMacStyle::drawPrimitive(), initFrom(), operator=(), QItemDelegate::setOptions(), QQC2::QWindowsStyle::styleHint(), QMacStyle::styleHint(), QQC2_NAMESPACE::QMacStyle::subControlRect(), and QMacStyle::subControlRect().
int QStyleOption::type |
Definition at line 58 of file qstyleoption.h.
Referenced by qstyleoption_cast(), qstyleoption_cast(), and QQC2::QWindowsStyle::styleHint().
int QStyleOption::version |
Definition at line 57 of file qstyleoption.h.
Referenced by qstyleoption_cast(), and qstyleoption_cast().