QStyle Class
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI. More…
| Header | #include <QStyle> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QObject |
List of all members, including inherited members
Public Types
| enum | StateFlag |
| typedef | State |
| enum | PrimitiveElement |
| enum | ControlElement |
| enum | SubElement |
| enum | PixelMetric |
| enum | ContentsType |
Public Functions
| ~QStyle() | |
| virtual void | drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const |
| virtual void | drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const |
| virtual QRect | subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget = nullptr) const |
| virtual int | pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const |
| virtual QSize | sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget = nullptr) const |
| virtual QPalette | standardPalette() 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.
| Constant | Description |
|---|---|
QStyle::CT_PushButton | A push button. |
QStyle::CT_CheckBox | A check box. |
QStyle::CT_LineEdit | A line edit. |
QStyle::CT_RadioButton | A radio button. |
QStyle::CT_ProgressBar | A progress bar. |
QStyle::CT_TabBarTab | A tab of a tab bar. |
QStyle::CT_ComboBox | A combo box. |
QStyle::CT_SpinBox | A spin box. |
QStyle::CT_ToolButton | A tool button with a text. |
QStyle::CT_MenuItem | An entry of a menu: the size of its text becomes the size of the entry. |
QStyle::CT_MenuBarItem | A title of a menu bar. |
enum QStyle::ControlElement
This enum names the elements that a style draws with drawControl().
| Constant | Description |
|---|---|
QStyle::CE_PushButton | A push button: bevel and label. |
QStyle::CE_PushButtonBevel | The bevel of a push button. |
QStyle::CE_PushButtonLabel | The label of a push button. |
QStyle::CE_CheckBox | A check box: indicator and label. |
QStyle::CE_CheckBoxLabel | The label of a check box. |
QStyle::CE_RadioButton | A radio button: indicator and label. |
QStyle::CE_RadioButtonLabel | The label of a radio button. |
QStyle::CE_Slider | A slider: groove and handle, described by a QStyleOptionSlider. |
QStyle::CE_ProgressBar | A progress bar: groove, bar and text, described by a QStyleOptionProgressBar. |
QStyle::CE_TabBarTab | One tab of a tab bar, described by a QStyleOptionTab. |
QStyle::CE_ComboBox | A combo box without its popup, described by a QStyleOptionComboBox. |
QStyle::CE_SpinBox | The frame and buttons of a spin box, described by a QStyleOptionSpinBox. |
QStyle::CE_GroupBox | A group box: frame and title, described by a QStyleOptionGroupBox. |
QStyle::CE_ScrollBar | A scroll bar: groove and handle, described by a QStyleOptionSlider. |
QStyle::CE_Header | One section of a header: background and text, described by a QStyleOptionHeader. |
QStyle::CE_Dial | A dial: the face, the handle and the notches, described by a QStyleOptionSlider. |
QStyle::CE_Splitter | The handle of a splitter, which is horizontal if the state has State_Horizontal. |
QStyle::CE_MenuItem | An entry of a menu, with a QStyleOptionMenuItem. |
QStyle::CE_MenuBarItem | A title in a menu bar, with a QStyleOptionMenuItem. |
QStyle::CE_MenuBarEmptyArea | The background of a menu bar. |
enum QStyle::PixelMetric
This enum names the sizes that a style provides to pixelMetric().
| Constant | Description |
|---|---|
QStyle::PM_ButtonMargin | The margin between the edge of a button and its label. |
QStyle::PM_DefaultFrameWidth | The width of the frame of a widget. |
QStyle::PM_IndicatorWidth | The width of a check box indicator. |
QStyle::PM_IndicatorHeight | The height of a check box indicator. |
QStyle::PM_CheckBoxLabelSpacing | The space between a check box indicator and its label. |
QStyle::PM_LayoutLeftMargin | The default left margin of a layout. |
QStyle::PM_LayoutTopMargin | The default top margin of a layout. |
QStyle::PM_LayoutRightMargin | The default right margin of a layout. |
QStyle::PM_LayoutBottomMargin | The default bottom margin of a layout. |
QStyle::PM_LayoutHorizontalSpacing | The default horizontal spacing of a layout. |
QStyle::PM_LayoutVerticalSpacing | The default vertical spacing of a layout. |
QStyle::PM_ExclusiveIndicatorWidth | The width of a radio button indicator. |
QStyle::PM_ExclusiveIndicatorHeight | The height of a radio button indicator. |
QStyle::PM_SliderThickness | The width of a slider across its direction, handle included. |
QStyle::PM_SliderLength | The length of the handle of a slider. |
QStyle::PM_SpinBoxButtonWidth | The width of the buttons of a spin box. |
QStyle::PM_ComboBoxArrowWidth | The width of the part of a combo box that has the arrow. |
QStyle::PM_ScrollBarExtent | The thickness of a scroll bar: the width of a vertical one, the height of a horizontal one. |
QStyle::PM_ScrollBarSliderMin | The shortest that the handle of a scroll bar gets. |
QStyle::PM_HeaderMargin | The space on each side of the text in a section of a header. |
QStyle::PM_HeaderDefaultSectionSizeHorizontal | The width of a section of a horizontal header, or of a column of a table. |
QStyle::PM_HeaderDefaultSectionSizeVertical | The height of a section of a vertical header, or of a row of a table. |
QStyle::PM_SplitterWidth | The width of the handle of a splitter. |
QStyle::PM_MenuBarItemSpacing | The 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().
| Constant | Description |
|---|---|
QStyle::PE_Frame | A generic frame. |
QStyle::PE_FrameFocusRect | The rectangle that shows the keyboard focus. |
QStyle::PE_PanelButtonCommand | The background of a push button. |
QStyle::PE_IndicatorCheckBox | The indicator of a check box. |
QStyle::PE_PanelLineEdit | The background of a line edit. |
QStyle::PE_FrameLineEdit | The frame of a line edit. |
QStyle::PE_IndicatorRadioButton | The indicator of a radio button. |
QStyle::PE_IndicatorArrowUp | An arrow that points up, as on a spin box button. |
QStyle::PE_IndicatorArrowDown | An arrow that points down, as on a combo box. |
QStyle::PE_FrameGroupBox | The frame of a group box. |
QStyle::PE_FrameTabWidget | The frame around the pages of a tab widget. |
QStyle::PE_PanelTipLabel | The background and the frame of a tool tip. |
QStyle::PE_IndicatorArrowLeft | An arrow that points left, as on a tool button. |
QStyle::PE_IndicatorArrowRight | An arrow that points right, as on a tool button. |
QStyle::PE_PanelStatusBar | The background of a status bar. |
QStyle::PE_PanelMenu | The 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>.
| Constant | Description |
|---|---|
QStyle::State_None | Nothing is set. |
QStyle::State_Enabled | The element is enabled. |
QStyle::State_Raised | The element is raised: not pressed. |
QStyle::State_Sunken | The element is pressed. |
QStyle::State_Off | A checkable element is not checked. |
QStyle::State_On | A checkable element is checked. |
QStyle::State_HasFocus | The element has the keyboard focus. |
QStyle::State_Selected | The element is selected, as the current tab of a tab bar is. |
QStyle::State_MouseOver | The mouse is over the element. |
QStyle::State_Active | The window of the element is active. |
QStyle::State_Horizontal | The 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.
| Constant | Description |
|---|---|
QStyle::SE_CheckBoxIndicator | The indicator of a check box. |
QStyle::SE_CheckBoxContents | The area of a check box that has the label. |
QStyle::SE_PushButtonContents | The area of a push button that has the label. |
QStyle::SE_RadioButtonIndicator | The indicator of a radio button. |
QStyle::SE_RadioButtonContents | The area of a radio button that has the label. |
QStyle::SE_LineEditContents | The area of a line edit in which the text is drawn. |
QStyle::SE_SliderGroove | The groove of a slider. |
QStyle::SE_SliderHandle | The handle of a slider, at the position in the QStyleOptionSlider. |
QStyle::SE_ProgressBarContents | The area of a progress bar that the bar and the text use. |
QStyle::SE_ComboBoxArrow | The part of a combo box that has the arrow. |
QStyle::SE_SpinBoxEditField | The part of a spin box in which the text is edited. |
QStyle::SE_SpinBoxUp | The button of a spin box that steps up. |
QStyle::SE_SpinBoxDown | The button of a spin box that steps down. |
QStyle::SE_GroupBoxIndicator | The check box in the title of a checkable group box. |
QStyle::SE_GroupBoxTitle | The title of a group box, with the check box if it has one. |
QStyle::SE_GroupBoxContents | The area inside the frame of a group box. |
QStyle::SE_ScrollBarSlider | The handle of a scroll bar, from the position, range and page step of a QStyleOptionSlider. |
Member Function Documentation
QStyle::QStyle()
Constructs a style.
QStyle::~QStyle()
Destroys the style.
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.
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.
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.
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.
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().
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.