6.0.0-rc4Source

QStyle Class

The QStyle class is an abstract base class that encapsulates the look and feel of a GUI. More…

Header#include <QStyle>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQObject

List of all members, including inherited members

Public Types

Public Functions

~QStyle()
virtual voiddrawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const
virtual voiddrawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const
virtual QRectsubElementRect(SubElement element, const QStyleOption *option, const QWidget *widget = nullptr) const
virtual intpixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const
virtual QSizesizeFromContents(ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget = nullptr) const
virtual QPalettestandardPalette() const

Protected Functions

QStyle()

Detailed Description

Widgets do not draw themselves with fixed colors and sizes; they ask the style. A style draws the primitive elements (frames, panels) and controls (buttons) from a QStyleOption that describes the state and rectangle, and answers questions about sizes. Nt has one style, the default, which is like Qt's Fusion style, and QApplication::setStyle() installs another one.

QStyleOptionButton option;
option.initFrom(button);
option.text = button->text();
button->style()->drawControl(QStyle::CE_PushButton, &option, &painter, button);

See also QStyleOption, QApplication::setStyle() and QWidget::setStyle().

Differences from Qt

The element set covers the widgets of Nt: buttons, check and radio buttons, line edits, sliders, progress bars, tabs, combo boxes, spin boxes and group boxes. There are no complex controls (drawComplexControl() and QStyle::ComplexControl), so the slider, combo box, spin box and group box are drawn as control elements with a QStyleOption subclass of their own, and no polish(), standardIcon(), styleHint(), hitTestComplexControl(), style sheets or QStyleFactory.

Member Type Documentation

enum QStyle::ContentsType

This enum names the widgets whose size sizeFromContents() computes.

ConstantDescription
QStyle::CT_PushButtonA push button.
QStyle::CT_CheckBoxA check box.
QStyle::CT_LineEditA line edit.
QStyle::CT_RadioButtonA radio button.
QStyle::CT_ProgressBarA progress bar.
QStyle::CT_TabBarTabA tab of a tab bar.
QStyle::CT_ComboBoxA combo box.
QStyle::CT_SpinBoxA spin box.
QStyle::CT_ToolButtonA tool button with a text.
QStyle::CT_MenuItemAn entry of a menu: the size of its text becomes the size of the entry.
QStyle::CT_MenuBarItemA title of a menu bar.

enum QStyle::ControlElement

This enum names the elements that a style draws with drawControl().

ConstantDescription
QStyle::CE_PushButtonA push button: bevel and label.
QStyle::CE_PushButtonBevelThe bevel of a push button.
QStyle::CE_PushButtonLabelThe label of a push button.
QStyle::CE_CheckBoxA check box: indicator and label.
QStyle::CE_CheckBoxLabelThe label of a check box.
QStyle::CE_RadioButtonA radio button: indicator and label.
QStyle::CE_RadioButtonLabelThe label of a radio button.
QStyle::CE_SliderA slider: groove and handle, described by a QStyleOptionSlider.
QStyle::CE_ProgressBarA progress bar: groove, bar and text, described by a QStyleOptionProgressBar.
QStyle::CE_TabBarTabOne tab of a tab bar, described by a QStyleOptionTab.
QStyle::CE_ComboBoxA combo box without its popup, described by a QStyleOptionComboBox.
QStyle::CE_SpinBoxThe frame and buttons of a spin box, described by a QStyleOptionSpinBox.
QStyle::CE_GroupBoxA group box: frame and title, described by a QStyleOptionGroupBox.
QStyle::CE_ScrollBarA scroll bar: groove and handle, described by a QStyleOptionSlider.
QStyle::CE_HeaderOne section of a header: background and text, described by a QStyleOptionHeader.
QStyle::CE_DialA dial: the face, the handle and the notches, described by a QStyleOptionSlider.
QStyle::CE_SplitterThe handle of a splitter, which is horizontal if the state has State_Horizontal.
QStyle::CE_MenuItemAn entry of a menu, with a QStyleOptionMenuItem.
QStyle::CE_MenuBarItemA title in a menu bar, with a QStyleOptionMenuItem.
QStyle::CE_MenuBarEmptyAreaThe background of a menu bar.

enum QStyle::PixelMetric

This enum names the sizes that a style provides to pixelMetric().

ConstantDescription
QStyle::PM_ButtonMarginThe margin between the edge of a button and its label.
QStyle::PM_DefaultFrameWidthThe width of the frame of a widget.
QStyle::PM_IndicatorWidthThe width of a check box indicator.
QStyle::PM_IndicatorHeightThe height of a check box indicator.
QStyle::PM_CheckBoxLabelSpacingThe space between a check box indicator and its label.
QStyle::PM_LayoutLeftMarginThe default left margin of a layout.
QStyle::PM_LayoutTopMarginThe default top margin of a layout.
QStyle::PM_LayoutRightMarginThe default right margin of a layout.
QStyle::PM_LayoutBottomMarginThe default bottom margin of a layout.
QStyle::PM_LayoutHorizontalSpacingThe default horizontal spacing of a layout.
QStyle::PM_LayoutVerticalSpacingThe default vertical spacing of a layout.
QStyle::PM_ExclusiveIndicatorWidthThe width of a radio button indicator.
QStyle::PM_ExclusiveIndicatorHeightThe height of a radio button indicator.
QStyle::PM_SliderThicknessThe width of a slider across its direction, handle included.
QStyle::PM_SliderLengthThe length of the handle of a slider.
QStyle::PM_SpinBoxButtonWidthThe width of the buttons of a spin box.
QStyle::PM_ComboBoxArrowWidthThe width of the part of a combo box that has the arrow.
QStyle::PM_ScrollBarExtentThe thickness of a scroll bar: the width of a vertical one, the height of a horizontal one.
QStyle::PM_ScrollBarSliderMinThe shortest that the handle of a scroll bar gets.
QStyle::PM_HeaderMarginThe space on each side of the text in a section of a header.
QStyle::PM_HeaderDefaultSectionSizeHorizontalThe width of a section of a horizontal header, or of a column of a table.
QStyle::PM_HeaderDefaultSectionSizeVerticalThe height of a section of a vertical header, or of a row of a table.
QStyle::PM_SplitterWidthThe width of the handle of a splitter.
QStyle::PM_MenuBarItemSpacingThe space between the titles of a menu bar, which is also the space before the first.

enum QStyle::PrimitiveElement

This enum names the elements that a style draws with drawPrimitive().

ConstantDescription
QStyle::PE_FrameA generic frame.
QStyle::PE_FrameFocusRectThe rectangle that shows the keyboard focus.
QStyle::PE_PanelButtonCommandThe background of a push button.
QStyle::PE_IndicatorCheckBoxThe indicator of a check box.
QStyle::PE_PanelLineEditThe background of a line edit.
QStyle::PE_FrameLineEditThe frame of a line edit.
QStyle::PE_IndicatorRadioButtonThe indicator of a radio button.
QStyle::PE_IndicatorArrowUpAn arrow that points up, as on a spin box button.
QStyle::PE_IndicatorArrowDownAn arrow that points down, as on a combo box.
QStyle::PE_FrameGroupBoxThe frame of a group box.
QStyle::PE_FrameTabWidgetThe frame around the pages of a tab widget.
QStyle::PE_PanelTipLabelThe background and the frame of a tool tip.
QStyle::PE_IndicatorArrowLeftAn arrow that points left, as on a tool button.
QStyle::PE_IndicatorArrowRightAn arrow that points right, as on a tool button.
QStyle::PE_PanelStatusBarThe background of a status bar.
QStyle::PE_PanelMenuThe background and the frame of a menu.

typedef QStyle::State

The State type is a typedef for QFlags<StateFlag>. It stores an OR combination of StateFlag values.

enum QStyle::StateFlag

This enum describes the state of an element that is drawn. The State type is a typedef for QFlags<StateFlag>.

ConstantDescription
QStyle::State_NoneNothing is set.
QStyle::State_EnabledThe element is enabled.
QStyle::State_RaisedThe element is raised: not pressed.
QStyle::State_SunkenThe element is pressed.
QStyle::State_OffA checkable element is not checked.
QStyle::State_OnA checkable element is checked.
QStyle::State_HasFocusThe element has the keyboard focus.
QStyle::State_SelectedThe element is selected, as the current tab of a tab bar is.
QStyle::State_MouseOverThe mouse is over the element.
QStyle::State_ActiveThe window of the element is active.
QStyle::State_HorizontalThe element is horizontal, as the handle of a splitter that divides left from right.

enum QStyle::SubElement

This enum names the parts of an element that subElementRect() finds.

ConstantDescription
QStyle::SE_CheckBoxIndicatorThe indicator of a check box.
QStyle::SE_CheckBoxContentsThe area of a check box that has the label.
QStyle::SE_PushButtonContentsThe area of a push button that has the label.
QStyle::SE_RadioButtonIndicatorThe indicator of a radio button.
QStyle::SE_RadioButtonContentsThe area of a radio button that has the label.
QStyle::SE_LineEditContentsThe area of a line edit in which the text is drawn.
QStyle::SE_SliderGrooveThe groove of a slider.
QStyle::SE_SliderHandleThe handle of a slider, at the position in the QStyleOptionSlider.
QStyle::SE_ProgressBarContentsThe area of a progress bar that the bar and the text use.
QStyle::SE_ComboBoxArrowThe part of a combo box that has the arrow.
QStyle::SE_SpinBoxEditFieldThe part of a spin box in which the text is edited.
QStyle::SE_SpinBoxUpThe button of a spin box that steps up.
QStyle::SE_SpinBoxDownThe button of a spin box that steps down.
QStyle::SE_GroupBoxIndicatorThe check box in the title of a checkable group box.
QStyle::SE_GroupBoxTitleThe title of a group box, with the check box if it has one.
QStyle::SE_GroupBoxContentsThe area inside the frame of a group box.
QStyle::SE_ScrollBarSliderThe handle of a scroll bar, from the position, range and page step of a QStyleOptionSlider.

Member Function Documentation

[protected] QStyle::QStyle()

Constructs a style.

[override] QStyle::~QStyle()

Destroys the style.

[virtual] void QStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const

Draws element as option describes, with painter. widget is the widget that is drawn, and can be nullptr.

[virtual] void QStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const

Draws element as option describes, with painter. widget is the widget that is drawn, and can be nullptr.

[virtual] int QStyle::pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const

Returns the value of metric, in pixels. option and widget may be nullptr.

[virtual] QSize QStyle::sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget = nullptr) const

Returns the size that a widget of type needs for contents of contentsSize: the contents plus the space that the style spends on frames and margins. option and widget describe the widget and may be nullptr.

[virtual] QPalette QStyle::standardPalette() const

Returns the palette that the application uses for its widgets when it has not been given one with QApplication::setPalette(). The default is the light palette of QPalette. A style that follows the color scheme of the desktop returns a dark palette when QStyleHints::colorScheme() is Qt::ColorScheme::Dark.

See also QApplication::palette() and QStyleHints::colorScheme().

[virtual] QRect QStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget = nullptr) const

Returns the rectangle of element for the widget that option describes. widget is that widget, and may be nullptr.