QStyle文档

前言

本文翻译自Qt官方文档,详细介绍了各成员/类型的作用,包含部分示例代码。

QStyle类的内容非常庞大,如需快速了解类成员和使用简介,请参见 QStyle简介。

一、QStyle Class

QStyle是一个抽象基类,封装了GUI的外观。

Qt包含一组QStyle子类,这些子类模拟了Qt支持的不同平台的样式(QWindowStyleQMacStyle等)。默认情况下,这些样式内置在Qt GUI模块中。样式也可以作为插件提供。Qt的内置小部件使用 QStyle来执行几乎所有的绘图操作 (这意味着几乎所有内置控件的部分,都有可能通过样式来控制),确保它们看起来与原生小部件完全相同。

下图显示了一个QComboBox在九种不同样式下的外观。
在这里插入图片描述

1. 设置Style

整个应用程序的样式可以使用QApplication::setStyle()函数设置。用户也可以使用-style命令行选项来指定样式:

./myapplication -style windows

如果未指定样式,Qt将为用户的平台或桌面环境选择最合适的样式。也可以使用QWidget::setStyle()函数在单个小部件上设置样式。

2. 创建样式感知的自定义Widgets

如果您正在开发自定义小部件并希望它们在所有平台上看起来都很好,可以使用QStyle函数来执行小部件绘图的部分操作,例如drawItemText()drawItemPixmap()drawPrimitive()drawControl()drawComplexControl()

大多数QStyle绘图函数需要四个参数:

  1. 一个枚举值。
    • 用于指定要绘制的图形元素。
  2. 一个QStyleOption
    • 指定如何、在何处渲染元素。
  3. 一个QPainter
    • 用于绘制元素。
  4. 一个QWidget(可选的)
    • 在其上执行绘制操作。

举个例子,如果你想在控件上画一个焦点矩形框,可以这样写:

	void paintEvent (QPaintEvent *event) override{QPainter painter (this);QStyleOptionFocusRect option;option.initFrom (this);option.backgroundColor = palette().color (QPalette::Background);style()->drawPrimitive (QStyle::PE_FrameFocusRect, &option, &painter, this);}

QStyleQStyleOption获取渲染图形元素所需的所有信息。widget作为最后一个参数传递,以防样式需要它来执行特殊效果(例如macOS上的动画默认按钮),但这不是强制的。实际上,通过正确设置QPainter,您可以使用QStyle任何绘图设备上绘图,而不仅仅是小部件。

QStyleOption有各种各样的子类,用于不同类型的可绘制图形元素。例如,PE_FrameFocusRect需要一个QStyleOptionFocusRect参数。

为了确保绘图操作尽可能快,QStyleOption及其子类具有公共数据成员。有关如何使用它的详细信息,请参阅QStyleOption类文档。

为了方便起见,Qt提供了QStylePainter类,它结合了QStyleQPainterQWidget。这使得编写以下代码成为可能:

QStylePainter painter(this);
...
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);

而不是:

QPinter painter(this);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);

3. 创建一个自定义Style

您可以创建自定义样式,来为您的应用程序创建自定义外观。

创建自定义样式有两种方法:

  1. 静态方法
    • 可以选择现有的QStyle类,子类化它,并重新实现虚函数以提供自定义行为,或者从头开始创建整个QStyle类。
  2. 动态方法
    • 可以在运行时修改系统样式的行为。

下面描述了静态方法。

动态方法在QProxyStyle中描述。

静态方法的第一步是选择一个Qt提供的样式,作为构建您的自定义样式的基础。您选择的QStyle类将取决于哪个样式最接近您想要的样式。您可以使用的最通用的类是QCommonStyle(而不是QStyle)。这是因为Qt要求其样式是QCommonStyles

根据想要更改的基样式的那些部分,必须重新实现用于绘制这些界面部分的函数。为了说明这一点,我们将修改由QWindowsStyle绘制的微调框箭头的外观。箭头是由drawPrimitive()函数绘制的原始元素,因此我们需要重新实现该函数。我们需要以下类声明:

class CustomStyle : public QProxyStyle {Q_OBJECT
public:CustomStyle();~CustomStyle(){}void drawPrimitive (PrimitiveElement element,const QStyleOption *option,QPainter *painter,const QWidget *wodget) const override;
};

为了绘制其向上和向下箭头,QSpinBox使用了PE_IndicatorSpinUpPE_IndicatorSpinDown基本元素。以下是如何重新实现drawPrimitive()函数以不同方式绘制它们:

void
CustomStyle::drawPrimitive (PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget
) const
{if (element == PE_IndicatorSpinUp || element == PE_IndicatorSpinDown) {QPolygon points (3);int x = option->rect.x();int y = option->rect.y();int w = option->rect.width() / 2;int h = option->rect.height() / 2;x += (option->rect.width() - w) / 2;y += (option->rect.height() - h) / 2;if (element == PE_IndicatorSpinUp) {points[0] = QPoint (x, y + h);points[1] = QPoint (x + w, y + h);points[2] = QPoint (x + w / 2, y);} else { // PE_SpinBoxDownpoints[0] = QPoint (x, y);points[1] = QPoint (x + w, y);points[2] = QPoint (x + w / 2, y + h);}if (option->state & State_Enabled) {painter->setPen (option->palette.mid().color());painter->setBrush (option->palette.buttonText());} else {painter->setPen (option->palette.buttonText().color());painter->setBrush (option->palette.mid());}painter->drawPolygon (points);} else {QProxyStyle::drawPrimitive (element, option, painter, widget);}
}

请注意,我们没有使用widget参数,除了将其传递给QCommonStyle::drawPrimitive()函数。正如前面提到的,有关要绘制的内容和绘制方式的信息由QStyleOption对象指定,因此不需要询问小部件。

如果您需要使用widget参数来获取其他信息,请确保它不是空指针,并且它是正确的类型,然后再使用它。例如:

const QSpinBox* spinBox = qobject_cast<const QSpinBox*>(widget);
if(spinBox){...
}

在实现自定义样式时,不能仅仅因为枚举值被称为PE_IndicatorSpinUp或PE_IndicatorSpinDown就假定该小部件是QSpinBox`。

关于这个主题的更多细节,请参阅The documentation for the Styles example 。

4. 使用自定义Style

在Qt应用程序中使用自定义样式有几种方法。最简单的方法是在创建QApplication对象之前,将自定义样式传递给QApplication::setStyle()静态函数:

 #include <QtWidgets>#include "customstyle.h"int main(int argc, char *argv[]){QApplication::setStyle(new CustomStyle);QApplication app(argc, argv);QSpinBox spinBox;spinBox.show();return app.exec();}

原生的:
在这里插入图片描述
自定义的:
在这里插入图片描述

您可以随时调用QApplication::setStyle(),但通过在构造函数之前调用它,可以确保不违背用户使用-style命令行选项设置的首选项。

您可能希望使您的自定义样式可用于其他应用程序,这些应用程序可能不是您的,因此无法重新编译。Qt插件系统使得可以将样式创建为插件。作为插件创建的样式在运行时由Qt本身作为共享对象加载。

有关如何创建样式插件的更多信息,请参阅 Qt Plugin documentation 。

编译您的插件并将其放入Qt的plugins/styles目录。现在,我们有一个可插拔的样式,Qt可以自动加载。要在现有应用程序中使用您的新样式,只需使用以下参数启动应用程序:

./myapplication -style custom

应用程序将使用您实现的自定义样式的外观。

5. Item Views中的Styles

视图中项目的绘制由委托完成。Qt的默认委托QStyledItemDelegate也用于计算项目的边界矩形及其子元素的各种项目数据角色。

请参阅QStyledItemDelegate类描述,以了解支持哪些数据类型和角色。您可以在Model/View编程中关于项目数据角色的信息。

QStyledItemDelegate绘制它的项目时,它会绘制CE_ItemViewItem,并使用CT_ItemViewItem计算它们的大小。

此外,它使用SE_ItemViewItemText来设置编辑器的大小。在实现用于自定义Item Views绘制的样式时,您需要检查QCommonStyle的实现(以及您的样式继承的任何其他子类)。

通过这种方式,您可以了解哪些样式元素以及如何绘制,然后您可以重新实现那些需要以不同方式绘制的元素的绘制。

此处提供一个小示例,其中自定义了项目背景的绘制:

	switch (element) {case PE_PanelItemViewItem: {painter->save();QPoint topLeft	   = option->rect.topLeft();QPoint bottomRight = option->rect.topRight();QLinearGradient backgroundGradient (topLeft, bottomRight);backgroundGradient.setColorAt (0.0, QColor (Qt::yellow).lighter (190));backgroundGradient.setColorAt (1.0, Qt::white);painter->fillRect(option->rect, QBrush(backgroundGradient);painter->restore();break;}default:QProxyStyle::drawPrimitive (element, option, painter, widget);}

基本元素PE_PanelItemViewItem负责绘制项目的背景,并在QCommonStyleCE_ItemViewItem实现中被调用。

要支持对新数据类型和项目数据角色的绘制,有必要创建一个自定义委托(Custom Delegate)。但如果您只需要支持默认委托实现的数据类型,自定义样式则不需要再伴随一个委托。

QStyledItemDelegate类描述提供了有关自定义委托的更多信息。

Item View的headers的绘制也是由样式完成的,这使得可以控制标题项的大小以及行和列的大小。

另外可以看看 QStyleOption, QStylePainter, Styles Example, Styles and Style Aware Widgets, QStyledItemDelegate, and Styling.

二、QStyle Member Type文档

1. enum QStyle::ComplexControl

enum QStyle::ComplexControl

此枚举描述了可用的复杂控件。复杂控件会因用户点击的位置或按下的键而表现不同行为。

ConstantValueDescription
QStyle::CC_SpinBox0A spinbox, like QSpinBox.
QStyle::CC_ComboBox1A combobox, like QComboBox.
QStyle::CC_ScrollBar2A scroll bar, like QScrollBar.
QStyle::CC_Slider3A slider, like QSlider.
QStyle::CC_ToolButton4A tool button, like QToolButton.
QStyle::CC_TitleBar5A title bar, like those used in QMdiSubWindow.
QStyle::CC_GroupBox7A group box, like QGroupBox.
QStyle::CC_Dial6A dial, like QDial.
QStyle::CC_MdiControls8The minimize, close, and normal button in the menu bar for a maximized MDI subwindow.
QStyle::CC_CustomBase 0xf0000000Base value for custom complex controls. Custom values must be greater than this value.

可以看看 SubControl and drawComplexControl().

2. enum QStyle::ContentsType

enum QStyle::ContentsType

此枚举描述了可用的内容类型。这些内容类型用于计算各种小部件的内容大小

ConstantValueDescription
QStyle::CT_CheckBox1A check box, like QCheckBox.
QStyle::CT_ComboBox4A combo box, like QComboBox.
QStyle::CT_HeaderSection19A header section, like QHeader.
QStyle::CT_LineEdit14A line edit, like QLineEdit.
QStyle::CT_Menu10A menu, like QMenu.
QStyle::CT_MenuBar9A menu bar, like QMenuBar.
QStyle::CT_MenuBarItem8A menu bar item, like the buttons in a QMenuBar.
QStyle::CT_MenuItem7A menu item, like QMenuItem.
QStyle::CT_ProgressBar6A progress bar, like QProgressBar.
QStyle::CT_PushButton0A push button, like QPushButton.
QStyle::CT_RadioButton2A radio button, like QRadioButton.
QStyle::CT_SizeGrip16A size grip, like QSizeGrip.
QStyle::CT_Slider12A slider, like QSlider.
QStyle::CT_ScrollBar13A scroll bar, like QScrollBar.
QStyle::CT_SpinBox15A spin box, like QSpinBox.
QStyle::CT_Splitter5A splitter, like QSplitter.
QStyle::CT_TabBarTab11A tab on a tab bar, like QTabBar.
QStyle::CT_TabWidget17A tab widget, like QTabWidget.
QStyle::CT_ToolButton3A tool button, like QToolButton.
QStyle::CT_GroupBox20A group box, like QGroupBox.
QStyle::CT_ItemViewItem22An item inside an item view.
QStyle::CT_CustomBase0xf0000000Base value for custom contents types. Custom values must be greater than this value.
QStyle::CT_MdiControls21The minimize, normal, and close button in the menu bar for a maximized MDI subwindow.

可以看看 sizeFromContents()。

3. enum QStyle::ControlElement

enum QStyle::ControlElement

此枚举表示一个控件元素。控件元素是小部件的一部分,用于执行某些操作或向用户显示信息。

ConstantValueDescription
QStyle::CE_PushButton0A QPushButton, draws CE_PushButtonBevel, CE_PushButtonLabel and PE_FrameFocusRect.
QStyle::CE_PushButtonBevel1The bevel and default indicator of a QPushButton.
QStyle::CE_PushButtonLabel2The label (an icon with text or pixmap) of a QPushButton.
QStyle::CE_DockWidgetTitle30Dock window title.
QStyle::CE_Splitter28Splitter handle; see also QSplitter.
QStyle::CE_CheckBox3A QCheckBox, draws a PE_IndicatorCheckBox, a CE_CheckBoxLabel and a PE_FrameFocusRect.
QStyle::CE_CheckBoxLabel4The label (text or pixmap) of a QCheckBox.
QStyle::CE_RadioButton5A QRadioButton, draws a PE_IndicatorRadioButton, a CE_RadioButtonLabel and a PE_FrameFocusRect.
QStyle::CE_RadioButtonLabel6The label (text or pixmap) of a QRadioButton.
QStyle::CE_TabBarTab7The tab and label within a QTabBar.
QStyle::CE_TabBarTabShape8The tab shape within a tab bar.
QStyle::CE_TabBarTabLabel9The label within a tab.
QStyle::CE_ProgressBar10A QProgressBar, draws CE_ProgressBarGroove, CE_ProgressBarContents and CE_ProgressBarLabel.
QStyle::CE_ProgressBarGroove11The groove where the progress indicator is drawn in a QProgressBar.
QStyle::CE_ProgressBarContents12The progress indicator of a QProgressBar.
QStyle::CE_ProgressBarLabel13The text label of a QProgressBar.
QStyle::CE_ToolButtonLabel22A tool button’s label.
QStyle::CE_MenuBarItem20A menu item in a QMenuBar.
QStyle::CE_MenuBarEmptyArea21The empty area of a QMenuBar.
QStyle::CE_MenuItem14A menu item in a QMenu.
QStyle::CE_MenuScroller15Scrolling areas in a QMenu when the style supports scrolling.
QStyle::CE_MenuTearoff18A menu item representing the tear off section of a QMenu.
QStyle::CE_MenuEmptyArea19The area in a menu without menu items.
QStyle::CE_MenuHMargin17The horizontal extra space on the left/right of a menu.
QStyle::CE_MenuVMargin16The vertical extra space on the top/bottom of a menu.
QStyle::CE_ToolBoxTab26The toolbox’s tab and label within a QToolBox.
QStyle::CE_SizeGrip27Window resize handle; see also QSizeGrip.
QStyle::CE_Header23A header.
QStyle::CE_HeaderSection24A header section.
QStyle::CE_HeaderLabel25The header’s label.
QStyle::CE_ScrollBarAddLine31Scroll bar line increase indicator. (i.e., scroll down); see also QScrollBar.
QStyle::CE_ScrollBarSubLine32Scroll bar line decrease indicator (i.e., scroll up).
QStyle::CE_ScrollBarAddPage33Scolllbar page increase indicator (i.e., page down).
QStyle::CE_ScrollBarSubPage34Scroll bar page decrease indicator (i.e., page up).
QStyle::CE_ScrollBarSlider35Scroll bar slider.
QStyle::CE_ScrollBarFirst36Scroll bar first line indicator (i.e., home).
QStyle::CE_ScrollBarLast37Scroll bar last line indicator (i.e., end).
QStyle::CE_RubberBand29Rubber band used in for example an icon view.
QStyle::CE_FocusFrame38Focus frame that is style controlled.
QStyle::CE_ItemViewItem45An item inside an item view.
QStyle::CE_CustomBase0xf0000000Base value for custom control elements; custom values must be greater than this value.
QStyle::CE_ComboBoxLabel39The label of a non-editable QComboBox.
QStyle::CE_ToolBar40A toolbar like QToolBar.
QStyle::CE_ToolBoxTabShape41The toolbox’s tab shape.
QStyle::CE_ToolBoxTabLabel42The toolbox’s tab label.
QStyle::CE_HeaderEmptyArea43The area of a header view where there are no header sections.
QStyle::CE_ShapedFrame46The frame with the shape specified in the QStyleOptionFrame; see QFrame.

可以看看drawControl()

4. enum QStyle::PixelMetric

enum QStyle::PixelMetric

这个枚举描述了各种可用的像素度量。像素度量是一种与样式相关的尺寸,由单个像素值表示。

ConstantValueDescription
QStyle::PM_ButtonMargin0Amount of whitespace between push button labels and the frame.
QStyle::PM_DockWidgetTitleBarButtonMargin76Amount of whitespace between dock widget’s title bar button labels and the frame.
QStyle::PM_ButtonDefaultIndicator1Width of the default-button indicator frame.
QStyle::PM_MenuButtonIndicator2Width of the menu button indicator proportional to the widget height.
QStyle::PM_ButtonShiftHorizontal3Horizontal contents shift of a button when the button is down.
QStyle::PM_ButtonShiftVertical4Vertical contents shift of a button when the button is down.
QStyle::PM_DefaultFrameWidth5Default frame width (usually 2).
QStyle::PM_SpinBoxFrameWidth6Frame width of a spin box, defaults to PM_DefaultFrameWidth.
QStyle::PM_ComboBoxFrameWidth7Frame width of a combo box, defaults to PM_DefaultFrameWidth.
QStyle::PM_MDIFrameWidthPM_MdiSubWindowFrameWidthObsolete. Use PM_MdiSubWindowFrameWidth instead.
QStyle::PM_MdiSubWindowFrameWidth44Frame width of an MDI window.
QStyle::PM_MDIMinimizedWidthPM_MdiSubWindowMinimizedWidthObsolete. Use PM_MdiSubWindowMinimizedWidth instead.
QStyle::PM_MdiSubWindowMinimizedWidth45Width of a minimized MDI window.
QStyle::PM_LayoutLeftMargin78Default left margin for a QLayout.
QStyle::PM_LayoutTopMargin79Default top margin for a QLayout.
QStyle::PM_LayoutRightMargin80Default right margin for a QLayout.
QStyle::PM_LayoutBottomMargin81Default bottom margin for a QLayout.
QStyle::PM_LayoutHorizontalSpacing82Default horizontal spacing for a QLayout.
QStyle::PM_LayoutVerticalSpacing83Default vertical spacing for a QLayout.
QStyle::PM_MaximumDragDistance8The maximum allowed distance between the mouse and a scrollbar when dragging. Exceeding the specified distance will cause the slider to jump back to the original position; a value of -1 disables this behavior.
QStyle::PM_ScrollBarExtent9Width of a vertical scroll bar and the height of a horizontal scroll bar.
QStyle::PM_ScrollBarSliderMin10The minimum height of a vertical scroll bar’s slider and the minimum width of a horizontal scroll bar’s slider.
QStyle::PM_SliderThickness11Total slider thickness.
QStyle::PM_SliderControlThickness12Thickness of the slider handle.
QStyle::PM_SliderLength13Length of the slider.
QStyle::PM_SliderTickmarkOffset14The offset between the tickmarks and the slider.
QStyle::PM_SliderSpaceAvailable15The available space for the slider to move.
QStyle::PM_DockWidgetSeparatorExtent16Width of a separator in a horizontal dock window and the height of a separator in a vertical dock window.
QStyle::PM_DockWidgetHandleExtent17Width of the handle in a horizontal dock window and the height of the handle in a vertical dock window.
QStyle::PM_DockWidgetFrameWidth18Frame width of a dock window.
QStyle::PM_DockWidgetTitleMargin73Margin of the dock window title.
QStyle::PM_MenuBarPanelWidth33Frame width of a menu bar, defaults to PM_DefaultFrameWidth.
QStyle::PM_MenuBarItemSpacing34Spacing between menu bar items.
QStyle::PM_MenuBarHMargin36Spacing between menu bar items and left/right of bar.
QStyle::PM_MenuBarVMargin35Spacing between menu bar items and top/bottom of bar.
QStyle::PM_ToolBarFrameWidth52Width of the frame around toolbars.
QStyle::PM_ToolBarHandleExtent53Width of a toolbar handle in a horizontal toolbar and the height of the handle in a vertical toolbar.
QStyle::PM_ToolBarItemMargin55Spacing between the toolbar frame and the items.
QStyle::PM_ToolBarItemSpacing54Spacing between toolbar items.
QStyle::PM_ToolBarSeparatorExtent56Width of a toolbar separator in a horizontal toolbar and the height of a separator in a vertical toolbar.
QStyle::PM_ToolBarExtensionExtent57Width of a toolbar extension button in a horizontal toolbar and the height of the button in a vertical toolbar.
QStyle::PM_TabBarTabOverlap19Number of pixels the tabs should overlap. (Currently only used in styles, not inside of QTabBar)
QStyle::PM_TabBarTabHSpace20Extra space added to the tab width.
QStyle::PM_TabBarTabVSpace21Extra space added to the tab height.
QStyle::PM_TabBarBaseHeight22Height of the area between the tab bar and the tab pages.
QStyle::PM_TabBarBaseOverlap23Number of pixels the tab bar overlaps the tab bar base.
QStyle::PM_TabBarScrollButtonWidth51
QStyle::PM_TabBarTabShiftHorizontal49Horizontal pixel shift when a tab is selected.
QStyle::PM_TabBarTabShiftVertical50Vertical pixel shift when a tab is selected.
QStyle::PM_ProgressBarChunkWidth24Width of a chunk in a progress bar indicator.
QStyle::PM_SplitterWidth25Width of a splitter.
QStyle::PM_TitleBarHeight26Height of the title bar.
QStyle::PM_IndicatorWidth37Width of a check box indicator.
QStyle::PM_IndicatorHeight38Height of a checkbox indicator.
QStyle::PM_ExclusiveIndicatorWidth39Width of a radio button indicator.
QStyle::PM_ExclusiveIndicatorHeight40Height of a radio button indicator.
QStyle::PM_MenuPanelWidth30Border width (applied on all sides) for a QMenu.
QStyle::PM_MenuHMargin28Additional border (used on left and right) for a QMenu.
QStyle::PM_MenuVMargin29Additional border (used for bottom and top) for a QMenu.
QStyle::PM_MenuScrollerHeight27Height of the scroller area in a QMenu.
QStyle::PM_MenuTearoffHeight31Height of a tear off area in a QMenu.
QStyle::PM_MenuDesktopFrameWidth32The frame width for the menu on the desktop.
QStyle::PM_HeaderMarkSize47The size of the sort indicator in a header.
QStyle::PM_HeaderGripMargin48The size of the resize grip in a header.
QStyle::PM_HeaderMargin46The size of the margin between the sort indicator and the text.
QStyle::PM_SpinBoxSliderHeight58The height of the optional spin box slider.
QStyle::PM_ToolBarIconSizePM_SpinBoxSliderHeight + 4Default tool bar icon size
QStyle::PM_SmallIconSize65Default small icon size
QStyle::PM_LargeIconSize66Default large icon size
QStyle::PM_FocusFrameHMargin68Horizontal margin that the focus frame will outset the widget by.
QStyle::PM_FocusFrameVMargin67Vertical margin that the focus frame will outset the widget by.
QStyle::PM_IconViewIconSize64The default size for icons in an icon view.
QStyle::PM_ListViewIconSize63The default size for icons in a list view.
QStyle::PM_ToolTipLabelFrameWidth69The frame width for a tool tip label.
QStyle::PM_CheckBoxLabelSpacing70The spacing between a check box indicator and its label.
QStyle::PM_RadioButtonLabelSpacing77The spacing between a radio button indicator and its label.
QStyle::PM_TabBarIconSize71The default icon size for a tab bar.
QStyle::PM_SizeGripSize72The size of a size grip.
QStyle::PM_MessageBoxIconSize74The size of the standard icons in a message box
QStyle::PM_ButtonIconSize75The default size of button icons
QStyle::PM_TextCursorWidth85The width of the cursor in a line edit or text edit
QStyle::PM_TabBar_ScrollButtonOverlap84The distance between the left and right buttons in a tab bar.
QStyle::PM_TabCloseIndicatorWidth86The default width of a close button on a tab in a tab bar.
QStyle::PM_TabCloseIndicatorHeight87The default height of a close button on a tab in a tab bar.
QStyle::PM_ScrollView_ScrollBarSpacing88Distance between frame and scrollbar with SH_ScrollView_FrameOnlyAroundContents set.
QStyle::PM_ScrollView_ScrollBarOverlap89Overlap between scroll bars and scroll content
QStyle::PM_SubMenuOverlap90The horizontal overlap between a submenu and its parent.
QStyle::PM_TreeViewIndentation91The indentation of items in a tree view. This enum value has been introduced in Qt 5.4.
QStyle::PM_HeaderDefaultSectionSizeHorizontal92The default size of sections in a horizontal header. This enum value has been introduced in Qt 5.5.
QStyle::PM_HeaderDefaultSectionSizeVertical93The default size of sections in a vertical header. This enum value has been introduced in Qt 5.5.
QStyle::PM_TitleBarButtonIconSize94The size of button icons on a title bar. This enum value has been introduced in Qt 5.8.
QStyle::PM_TitleBarButtonSize95The size of buttons on a title bar. This enum value has been introduced in Qt 5.8.
QStyle::PM_CustomBase0xf0000000Base value for custom pixel metrics. Custom values must be greater than this value.

5. enum QStyle::PrimitiveElement

enum QStyle::PrimitiveElement

这个枚举描述了各种原始元素。原始元素是常见的图形用户界面元素,例如复选框指示器或按钮斜角。

ConstantValueDescription
QStyle::PE_FrameStatusBarPE_FrameStatusBarItemObsolete. Use PE_FrameStatusBarItem instead.
QStyle::PE_PanelButtonCommand13Button used to initiate an action, for example, a QPushButton.
QStyle::PE_FrameDefaultButton1This frame around a default button, e.g. in a dialog.
QStyle::PE_PanelButtonBevel14Generic panel with a button bevel.
QStyle::PE_PanelButtonTool15Panel for a Tool button, used with QToolButton.
QStyle::PE_PanelLineEdit18Panel for a QLineEdit.
QStyle::PE_IndicatorButtonDropDown24Indicator for a drop down button, for example, a tool button that displays a menu.
QStyle::PE_FrameFocusRect3Generic focus indicator.
QStyle::PE_IndicatorArrowUp22Generic Up arrow.
QStyle::PE_IndicatorArrowDown19Generic Down arrow.
QStyle::PE_IndicatorArrowRight21Generic Right arrow.
QStyle::PE_IndicatorArrowLeft20Generic Left arrow.
QStyle::PE_IndicatorSpinUp35Up symbol for a spin widget, for example a QSpinBox.
QStyle::PE_IndicatorSpinDown32Down symbol for a spin widget.
QStyle::PE_IndicatorSpinPlus34Increase symbol for a spin widget.
QStyle::PE_IndicatorSpinMinus33Decrease symbol for a spin widget.
QStyle::PE_IndicatorItemViewItemCheck25On/off indicator for a view item.
QStyle::PE_IndicatorCheckBox26On/off indicator, for example, a QCheckBox.
QStyle::PE_IndicatorRadioButton31Exclusive on/off indicator, for example, a QRadioButton.
QStyle::PE_IndicatorDockWidgetResizeHandle27Resize handle for dock windows.
QStyle::PE_Frame0Generic frame
QStyle::PE_FrameMenu6Frame for popup windows/menus; see also QMenu.
QStyle::PE_PanelMenuBar16Panel for menu bars.
QStyle::PE_PanelScrollAreaCorner40Panel at the bottom-right (or bottom-left) corner of a scroll area.
QStyle::PE_FrameDockWidget2Panel frame for dock windows and toolbars.
QStyle::PE_FrameTabWidget8Frame for tab widgets.
QStyle::PE_FrameLineEdit5Panel frame for line edits.
QStyle::PE_FrameGroupBox4Panel frame around group boxes.
QStyle::PE_FrameButtonBevel10Panel frame for a button bevel.
QStyle::PE_FrameButtonTool11Panel frame for a tool button.
QStyle::PE_IndicatorHeaderArrow28Arrow used to indicate sorting on a list or table header.
QStyle::PE_FrameStatusBarItem7Frame for an item of a status bar; see also QStatusBar.
QStyle::PE_FrameWindow9Frame around a MDI window or a docking window.
QStyle::PE_IndicatorMenuCheckMark29Check mark used in a menu.
QStyle::PE_IndicatorProgressChunk30Section of a progress bar indicator; see also QProgressBar.
QStyle::PE_IndicatorBranch23Lines used to represent the branch of a tree in a tree view.
QStyle::PE_IndicatorToolBarHandle36The handle of a toolbar.
QStyle::PE_IndicatorToolBarSeparator37The separator in a toolbar.
QStyle::PE_PanelToolBar17The panel for a toolbar.
QStyle::PE_PanelTipLabel38The panel for a tip label.
QStyle::PE_FrameTabBarBase12The frame that is drawn for a tab bar, ususally drawn for a tab bar that isn’t part of a tab widget.
QStyle::PE_IndicatorTabTear39Deprecated. Use PE_IndicatorTabTearLeft instead.
QStyle::PE_IndicatorTabTearLeftPE_IndicatorTabTearAn indicator that a tab is partially scrolled out on the left side of the visible tab bar when there are many tabs.
QStyle::PE_IndicatorTabTearRight49An indicator that a tab is partially scrolled out on the right side of the visible tab bar when there are many tabs.
QStyle::PE_IndicatorColumnViewArrow42An arrow in a QColumnView.
QStyle::PE_Widget41A plain QWidget.
QStyle::PE_CustomBase0xf000000Base value for custom primitive elements. All values above this are reserved for custom use. Custom values must be greater than this value.
QStyle::PE_IndicatorItemViewItemDrop43An indicator that is drawn to show where an item in an item view is about to be dropped during a drag-and-drop operation in an item view.
QStyle::PE_PanelItemViewItem44The background for an item in an item view.
QStyle::PE_PanelItemViewRow45The background of a row in an item view.
QStyle::PE_PanelStatusBar46The panel for a status bar.
QStyle::PE_IndicatorTabClose47The close button on a tab bar.
QStyle::PE_PanelMenu48The panel for a menu.

可以看看drawPrimitive();

6. enum QStyle::RequestSoftwareInputPanel

enum QStyle::RequestSoftwareInputPanel

这个枚举描述了在什么情况下具有输入功能的小部件会请求软件输入面板。

ConstantValueDescription
QStyle::RSIP_OnMouseClickAndAlreadyFocused0Requests an input panel if the user clicks on the widget, but only if it is already focused.
QStyle::RSIP_OnMouseClick1Requests an input panel if the user clicks on the widget.

7. enum QStyleStandardPixmap

enum QStyle::StandardPixmap

这个枚举描述了可用的标准像素图。标准像素图是可以遵循某些现有GUI样式或指南的像素图。

ConstantValueDescription
QStyle::SP_TitleBarMinButton1Minimize button on title bars (e.g., in QMdiSubWindow).
QStyle::SP_TitleBarMenuButton0Menu button on a title bar.
QStyle::SP_TitleBarMaxButton2Maximize button on title bars.
QStyle::SP_TitleBarCloseButton3Close button on title bars.
QStyle::SP_TitleBarNormalButton4Normal (restore) button on title bars.
QStyle::SP_TitleBarShadeButton5Shade button on title bars.
QStyle::SP_TitleBarUnshadeButton6Unshade button on title bars.
QStyle::SP_TitleBarContextHelpButton7The Context help button on title bars.
QStyle::SP_MessageBoxInformation9The “information” icon.
QStyle::SP_MessageBoxWarning10The “warning” icon.
QStyle::SP_MessageBoxCritical11The “critical” icon.
QStyle::SP_MessageBoxQuestion12The “question” icon.
QStyle::SP_DesktopIcon13The “desktop” icon.
QStyle::SP_TrashIcon14The “trash” icon.
QStyle::SP_ComputerIcon15The “My computer” icon.
QStyle::SP_DriveFDIcon16The floppy icon.
QStyle::SP_DriveHDIcon17The harddrive icon.
QStyle::SP_DriveCDIcon18The CD icon.
QStyle::SP_DriveDVDIcon19The DVD icon.
QStyle::SP_DriveNetIcon20The network icon.
QStyle::SP_DirHomeIcon56The home directory icon.
QStyle::SP_DirOpenIcon21The open directory icon.
QStyle::SP_DirClosedIcon22The closed directory icon.
QStyle::SP_DirIcon38The directory icon.
QStyle::SP_DirLinkIcon23The link to directory icon.
QStyle::SP_DirLinkOpenIcon24The link to open directory icon.
QStyle::SP_FileIcon25The file icon.
QStyle::SP_FileLinkIcon26The link to file icon.
QStyle::SP_FileDialogStart29The “start” icon in a file dialog.
QStyle::SP_FileDialogEnd30The “end” icon in a file dialog.
QStyle::SP_FileDialogToParent31The “parent directory” icon in a file dialog.
QStyle::SP_FileDialogNewFolder32The “create new folder” icon in a file dialog.
QStyle::SP_FileDialogDetailedView33The detailed view icon in a file dialog.
QStyle::SP_FileDialogInfoView34The file info icon in a file dialog.
QStyle::SP_FileDialogContentsView35The contents view icon in a file dialog.
QStyle::SP_FileDialogListView36The list view icon in a file dialog.
QStyle::SP_FileDialogBack37The back arrow in a file dialog.
QStyle::SP_DockWidgetCloseButton8Close button on dock windows (see also QDockWidget).
QStyle::SP_ToolBarHorizontalExtensionButton27Extension button for horizontal toolbars.
QStyle::SP_ToolBarVerticalExtensionButton28Extension button for vertical toolbars.
QStyle::SP_DialogOkButton39Icon for a standard OK button in a QDialogButtonBox.
QStyle::SP_DialogCancelButton40Icon for a standard Cancel button in a QDialogButtonBox.
QStyle::SP_DialogHelpButton41Icon for a standard Help button in a QDialogButtonBox.
QStyle::SP_DialogOpenButton42Icon for a standard Open button in a QDialogButtonBox.
QStyle::SP_DialogSaveButton43Icon for a standard Save button in a QDialogButtonBox.
QStyle::SP_DialogCloseButton44Icon for a standard Close button in a QDialogButtonBox.
QStyle::SP_DialogApplyButton45Icon for a standard Apply button in a QDialogButtonBox.
QStyle::SP_DialogResetButton46Icon for a standard Reset button in a QDialogButtonBox.
QStyle::SP_DialogDiscardButton47Icon for a standard Discard button in a QDialogButtonBox.
QStyle::SP_DialogYesButton48Icon for a standard Yes button in a QDialogButtonBox.
QStyle::SP_DialogNoButton49Icon for a standard No button in a QDialogButtonBox.
QStyle::SP_ArrowUp50Icon arrow pointing up.
QStyle::SP_ArrowDown51Icon arrow pointing down.
QStyle::SP_ArrowLeft52Icon arrow pointing left.
QStyle::SP_ArrowRight53Icon arrow pointing right.
QStyle::SP_ArrowBack54Equivalent to SP_ArrowLeft when the current layout direction is Qt::LeftToRight, otherwise SP_ArrowRight.
QStyle::SP_ArrowForward55Equivalent to SP_ArrowRight when the current layout direction is Qt::LeftToRight, otherwise SP_ArrowLeft.
QStyle::SP_CommandLink57Icon used to indicate a Vista style command link glyph.
QStyle::SP_VistaShield58Icon used to indicate UAC prompts on Windows Vista. This will return a null pixmap or icon on all other platforms.
QStyle::SP_BrowserReload59Icon indicating that the current page should be reloaded.
QStyle::SP_BrowserStop60Icon indicating that the page loading should stop.
QStyle::SP_MediaPlay61Icon indicating that media should begin playback.
QStyle::SP_MediaStop62Icon indicating that media should stop playback.
QStyle::SP_MediaPause63Icon indicating that media should pause playback.
QStyle::SP_MediaSkipForward64Icon indicating that media should skip forward.
QStyle::SP_MediaSkipBackward65Icon indicating that media should skip backward.
QStyle::SP_MediaSeekForward66Icon indicating that media should seek forward.
QStyle::SP_MediaSeekBackward67Icon indicating that media should seek backward.
QStyle::SP_MediaVolume68Icon indicating a volume control.
QStyle::SP_MediaVolumeMuted69Icon indicating a muted volume control.
QStyle::SP_LineEditClearButton70Icon for a standard clear button in a QLineEdit. This enum value was added in Qt 5.2.
QStyle::SP_DialogYesToAllButton71Icon for a standard YesToAll button in a QDialogButtonBox. This enum value was added in Qt 5.14.
QStyle::SP_DialogNoToAllButton72Icon for a standard NoToAll button in a QDialogButtonBox. This enum value was added in Qt 5.14.
QStyle::SP_DialogSaveAllButton73Icon for a standard SaveAll button in a QDialogButtonBox. This enum value was added in Qt 5.14.
QStyle::SP_DialogAbortButton74Icon for a standard Abort button in a QDialogButtonBox. This enum value was added in Qt 5.14.
QStyle::SP_DialogRetryButton75Icon for a standard Retry button in a QDialogButtonBox. This enum value was added in Qt 5.14.
QStyle::SP_DialogIgnoreButton76Icon for a standard Ignore button in a QDialogButtonBox. This enum value was added in Qt 5.14.
QStyle::SP_RestoreDefaultsButton77Icon for a standard RestoreDefaults button in a QDialogButtonBox. This enum value was added in Qt 5.14.
QStyle::SP_CustomBase0xf0000000Base value for custom standard pixmaps; custom values must be greater than this value.

可以看看 standardIcon().

8. enum QStyle::StateFlag

enum QStyle::StateFlag
flags QStyle::State

这个枚举描述了绘制原始元素(Primitive Elements)时使用的flags。

请注意,并不是所有原始元素都会使用所有这些标志,并且这些标志对不同的项目可能有不同的含义。

ConstantValueDescription
QStyle::State_None0x00000000Indicates that the widget does not have a state.
QStyle::State_Active0x00010000Indicates that the widget is active.
QStyle::State_AutoRaise0x00001000Used to indicate if auto-raise appearance should be used on a tool button.
QStyle::State_Children0x00080000Used to indicate if an item view branch has children.
QStyle::State_DownArrow0x00000040Used to indicate if a down arrow should be visible on the widget.
QStyle::State_Editing0x00400000Used to indicate if an editor is opened on the widget.
QStyle::State_Enabled0x00000001Used to indicate if the widget is enabled.
QStyle::State_HasEditFocus0x01000000Used to indicate if the widget currently has edit focus.
QStyle::State_HasFocus0x00000100Used to indicate if the widget has focus.
QStyle::State_Horizontal0x00000080Used to indicate if the widget is laid out horizontally, for example. a tool bar.
QStyle::State_KeyboardFocusChange0x00800000Used to indicate if the focus was changed with the keyboard, e.g., tab, backtab or shortcut.
QStyle::State_MouseOver0x00002000Used to indicate if the widget is under the mouse.
QStyle::State_NoChange0x00000010Used to indicate a tri-state checkbox.
QStyle::State_Off0x00000008Used to indicate if the widget is not checked.
QStyle::State_On0x00000020Used to indicate if the widget is checked.
QStyle::State_Raised0x00000002Used to indicate if a button is raised.
QStyle::State_ReadOnly0x02000000Used to indicate if a widget is read-only.
QStyle::State_Selected0x00008000Used to indicate if a widget is selected.
QStyle::State_Item0x00100000Used by item views to indicate if a horizontal branch should be drawn.
QStyle::State_Open0x00040000Used by item views to indicate if the tree branch is open.
QStyle::State_Sibling0x00200000Used by item views to indicate if a vertical line needs to be drawn (for siblings).
QStyle::State_Sunken0x00000004Used to indicate if the widget is sunken or pressed.
QStyle::State_UpArrow0x00004000Used to indicate if an up arrow should be visible on the widget.
QStyle::State_Mini0x08000000Used to indicate a mini style Mac widget or button.
QStyle::State_Small0x04000000Used to indicate a small style Mac widget or button.

State 类型是 QFlags<StateFlag> 的 typedef。它存储 StateFlag 值的 OR 组合。

可以看看 drawPrimitive()

9. enum QStyle::StyleHint

enum QStyle::StyleHint

这句话描述了可用的样式hints。样式提示是一种整体外观和/或feel的提示。

ConstantValueDescription
QStyle::SH_EtchDisabledText0Disabled text is “etched” as it is on Windows.
QStyle::SH_DitherDisabledText1Disabled text is dithered as it is on Motif.
QStyle::SH_ScrollBar_ContextMenu62Whether or not a scroll bar has a context menu.
QStyle::SH_ScrollBar_MiddleClickAbsolutePosition2A boolean value. If true, middle clicking on a scroll bar causes the slider to jump to that position. If false, middle clicking is ignored.
QStyle::SH_ScrollBar_LeftClickAbsolutePosition39A boolean value. If true, left clicking on a scroll bar causes the slider to jump to that position. If false, left clicking will behave as appropriate for each control.
QStyle::SH_ScrollBar_ScrollWhenPointerLeavesControl3A boolean value. If true, when clicking a scroll bar SubControl, holding the mouse button down and moving the pointer outside the SubControl, the scroll bar continues to scroll. If false, the scollbar stops scrolling when the pointer leaves the SubControl.
QStyle::SH_ScrollBar_RollBetweenButtons63A boolean value. If true, when clicking a scroll bar button (SC_ScrollBarAddLine or SC_ScrollBarSubLine) and dragging over to the opposite button (rolling) will press the new button and release the old one. When it is false, the original button is released and nothing happens (like a push button).
QStyle::SH_TabBar_Alignment5The alignment for tabs in a QTabWidget. Possible values are Qt::AlignLeft, Qt::AlignCenter and Qt::AlignRight.
QStyle::SH_Header_ArrowAlignment6The placement of the sorting indicator may appear in list or table headers. Possible values are Qt::Alignment values (that is, an OR combination of Qt::AlignmentFlag flags).
QStyle::SH_Slider_SnapToValue7Sliders snap to values while moving, as they do on Windows.
QStyle::SH_Slider_SloppyKeyEvents8Key presses handled in a sloppy manner, i.e., left on a vertical slider subtracts a line.
QStyle::SH_ProgressDialog_CenterCancelButton9Center button on progress dialogs, otherwise right aligned.
QStyle::SH_ProgressDialog_TextLabelAlignment10The alignment for text labels in progress dialogs; Qt::AlignCenter on Windows, Qt::AlignVCenter otherwise.
QStyle::SH_PrintDialog_RightAlignButtons11Right align buttons in the print dialog, as done on Windows.
QStyle::SH_MainWindow_SpaceBelowMenuBar12One or two pixel space between the menu bar and the dockarea, as done on Windows.
QStyle::SH_FontDialog_SelectAssociatedText13Select the text in the line edit, or when selecting an item from the listbox, or when the line edit receives focus, as done on Windows.
QStyle::SH_Menu_KeyboardSearch66Typing causes a menu to be search for relevant items, otherwise only mnemnonic is considered.
QStyle::SH_Menu_AllowActiveAndDisabled14Allows disabled menu items to be active.
QStyle::SH_Menu_SpaceActivatesItem15Pressing the space bar activates the item, as done on Motif.
QStyle::SH_Menu_SubMenuPopupDelay16The number of milliseconds to wait before opening a submenu (256 on Windows, 96 on Motif).
QStyle::SH_Menu_Scrollable30Whether popup menus must support scrolling.
QStyle::SH_Menu_SloppySubMenus33Whether popup menus must support the user moving the mouse cursor to a submenu while crossing other items of the menu. This is supported on most modern desktop platforms.
QStyle::SH_Menu_SubMenuUniDirection106Since Qt 5.5. If the cursor has to move towards the submenu (like it is on macOS), or if the cursor can move in any direction as long as it reaches the submenu before the sloppy timeout.
QStyle::SH_Menu_SubMenuUniDirectionFailCount107Since Qt 5.5. When SH_Menu_SubMenuUniDirection is defined this enum defines the number of failed mouse moves before the sloppy submenu is discarded. This can be used to control the “strictness” of the uni direction algorithm.
QStyle::SH_Menu_SubMenuSloppySelectOtherActions108Since Qt 5.5. Should other action items be selected when the mouse moves towards a sloppy submenu.
QStyle::SH_Menu_SubMenuSloppyCloseTimeout109Since Qt 5.5. The timeout used to close sloppy submenus.
QStyle::SH_Menu_SubMenuResetWhenReenteringParent110Since Qt 5.5. When entering parent from child submenu, should the sloppy state be reset, effectively closing the child and making the current submenu active.
QStyle::SH_Menu_SubMenuDontStartSloppyOnLeave111Since Qt 5.5. Do not start sloppy timers when the mouse leaves a sub-menu.
QStyle::SH_ScrollView_FrameOnlyAroundContents17Whether scrollviews draw their frame only around contents (like Motif), or around contents, scroll bars and corner widgets (like Windows).
QStyle::SH_MenuBar_AltKeyNavigation18Menu bars items are navigable by pressing Alt, followed by using the arrow keys to select the desired item.
QStyle::SH_ComboBox_ListMouseTracking19Mouse tracking in combobox drop-down lists.
QStyle::SH_Menu_MouseTracking20Mouse tracking in popup menus.
QStyle::SH_MenuBar_MouseTracking21Mouse tracking in menu bars.
QStyle::SH_Menu_FillScreenWithScroll45Whether scrolling popups should fill the screen as they are scrolled.
QStyle::SH_Menu_SelectionWrap74Whether popups should allow the selections to wrap, that is when selection should the next item be the first item.
QStyle::SH_ItemView_ChangeHighlightOnFocus22Gray out selected items when losing focus.
QStyle::SH_Widget_ShareActivation23Turn on sharing activation with floating modeless dialogs.
QStyle::SH_TabBar_SelectMouseType4Which type of mouse event should cause a tab to be selected.
QStyle::SH_ListViewExpand_SelectMouseType40Which type of mouse event should cause a list view expansion to be selected.
QStyle::SH_TabBar_PreferNoArrows38Whether a tab bar should suggest a size to prevent scoll arrows.
QStyle::SH_ComboBox_Popup25Allows popups as a combobox drop-down menu.
QStyle::SH_Workspace_FillSpaceOnMaximize24The workspace should maximize the client area.
QStyle::SH_TitleBar_NoBorder26The title bar has no border.
QStyle::SH_ScrollBar_StopMouseOverSliderSH_Slider_StopMouseOverSliderObsolete. Use SH_Slider_StopMouseOverSlider instead.
QStyle::SH_Slider_StopMouseOverSlider27Stops auto-repeat when the slider reaches the mouse position.
QStyle::SH_BlinkCursorWhenTextSelected28Whether cursor should blink when text is selected.
QStyle::SH_RichText_FullWidthSelection29Whether richtext selections should extend to the full width of the document.
QStyle::SH_GroupBox_TextLabelVerticalAlignment31How to vertically align a group box’s text label.
QStyle::SH_GroupBox_TextLabelColor32How to paint a group box’s text label.
QStyle::SH_DialogButtons_DefaultButton36Which button gets the default status in a dialog’s button widget.
QStyle::SH_ToolBox_SelectedPageTitleBold37Boldness of the selected page title in a QToolBox.
QStyle::SH_LineEdit_PasswordCharacter35The Unicode character to be used for passwords.
QStyle::SH_LineEdit_PasswordMaskDelay104Determines the delay before visible character is masked with password character, in milliseconds. This enum value was added in Qt 5.4.
QStyle::SH_Table_GridLineColor34The RGBA value of the grid for a table.
QStyle::SH_UnderlineShortcut41Whether shortcuts are underlined.
QStyle::SH_SpellCheckUnderlineStyle72Obsolete. Use SpellCheckUnderlineStyle hint in QPlatformTheme instead.
QStyle::SH_SpinBox_AnimateButton42Animate a click when up or down is pressed in a spin box.
QStyle::SH_SpinBox_KeyPressAutoRepeatRate43Auto-repeat interval for spinbox key presses.
QStyle::SH_SpinBox_ClickAutoRepeatRate44Auto-repeat interval for spinbox mouse clicks.
QStyle::SH_SpinBox_ClickAutoRepeatThreshold84Auto-repeat threshold for spinbox mouse clicks.
QStyle::SH_ToolTipLabel_Opacity46An integer indicating the opacity for the tip label, 0 is completely transparent, 255 is completely opaque.
QStyle::SH_DrawMenuBarSeparator47Indicates whether or not the menu bar draws separators.
QStyle::SH_TitleBar_ModifyNotification48Indicates if the title bar should show a ‘*’ for windows that are modified.
QStyle::SH_Button_FocusPolicy49The default focus policy for buttons.
QStyle::SH_CustomBase0xf0000000Base value for custom style hints. Custom values must be greater than this value.
QStyle::SH_MessageBox_UseBorderForButtonSpacing50A boolean indicating what the to use the border of the buttons (computed as half the button height) for the spacing of the button in a message box.
QStyle::SH_MessageBox_CenterButtons73A boolean indicating whether the buttons in the message box should be centered or not (see QDialogButtonBox::setCentered()).
QStyle::SH_MessageBox_TextInteractionFlags70A boolean indicating if the text in a message box should allow user interfactions (e.g. selection) or not.
QStyle::SH_TitleBar_AutoRaise51A boolean indicating whether controls on a title bar ought to update when the mouse is over them.
QStyle::SH_ToolButton_PopupDelay52An int indicating the popup delay in milliseconds for menus attached to tool buttons.
QStyle::SH_FocusFrame_Mask53The mask of the focus frame.
QStyle::SH_RubberBand_Mask54The mask of the rubber band.
QStyle::SH_WindowFrame_Mask55The mask of the window frame.
QStyle::SH_SpinControls_DisableOnBounds56Determines if the spin controls will shown as disabled when reaching the spin range boundary.
QStyle::SH_Dial_BackgroundRole57Defines the style’s preferred background role (as QPalette::ColorRole) for a dial widget.
QStyle::SH_ComboBox_LayoutDirection58The layout direction for the combo box. By default it should be the same as indicated by the QStyleOption::direction variable.
QStyle::SH_ItemView_EllipsisLocation59The location where ellipses should be added for item text that is too long to fit in an view item.
QStyle::SH_ItemView_ShowDecorationSelected60When an item in an item view is selected, also highlight the branch or other decoration.
QStyle::SH_ItemView_ActivateItemOnSingleClick61Emit the activated signal when the user single clicks on an item in an item in an item view. Otherwise the signal is emitted when the user double clicks on an item.
QStyle::SH_Slider_AbsoluteSetButtons64Which mouse buttons cause a slider to set the value to the position clicked on.
QStyle::SH_Slider_PageSetButtons65Which mouse buttons cause a slider to page step the value.
QStyle::SH_TabBar_ElideMode67The default eliding style for a tab bar.
QStyle::SH_DialogButtonLayout68Controls how buttons are laid out in a QDialogButtonBox, returns a QDialogButtonBox::ButtonLayout enum.
QStyle::SH_WizardStyle79Controls the look and feel of a QWizard. Returns a QWizard::WizardStyle enum.
QStyle::SH_FormLayoutWrapPolicy86Provides a default for how rows are wrapped in a QFormLayout. Returns a QFormLayout::RowWrapPolicy enum.
QStyle::SH_FormLayoutFieldGrowthPolicy89Provides a default for how fields can grow in a QFormLayout. Returns a QFormLayout::FieldGrowthPolicy enum.
QStyle::SH_FormLayoutFormAlignment90Provides a default for how a QFormLayout aligns its contents within the available space. Returns a Qt::Alignment enum.
QStyle::SH_FormLayoutLabelAlignment91Provides a default for how a QFormLayout aligns labels within the available space. Returns a Qt::Alignment enum.
QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren80Controls whether the tree view will select the first child when it is exapanded and the right arrow key is pressed.
QStyle::SH_ComboBox_PopupFrameStyle69The frame style used when drawing a combobox popup menu.
QStyle::SH_DialogButtonBox_ButtonsHaveIcons71Indicates whether or not StandardButtons in QDialogButtonBox should have icons or not.
QStyle::SH_ItemView_MovementWithoutUpdatingSelection75The item view is able to indicate a current item without changing the selection.
QStyle::SH_ToolTip_Mask76The mask of a tool tip.
QStyle::SH_FocusFrame_AboveWidget77The FocusFrame is stacked above the widget that it is “focusing on”.
QStyle::SH_TextControl_FocusIndicatorTextCharFormat78Specifies the text format used to highlight focused anchors in rich text documents displayed for example in QTextBrowser. The format has to be a QTextCharFormat returned in the variant of the QStyleHintReturnVariant return value. The QTextFormat::OutlinePen property is used for the outline and QTextFormat::BackgroundBrush for the background of the highlighted area.
QStyle::SH_Menu_FlashTriggeredItem82Flash triggered item.
QStyle::SH_Menu_FadeOutOnHide83Fade out the menu instead of hiding it immediately.
QStyle::SH_TabWidget_DefaultTabPosition87Default position of the tab bar in a tab widget.
QStyle::SH_ToolBar_Movable88Determines if the tool bar is movable by default.
QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea85Whether QTreeView paints alternating row colors for the area that does not have any items.
QStyle::SH_Menu_Mask81The mask for a popup menu.
QStyle::SH_ItemView_DrawDelegateFrame92Determines if there should be a frame for a delegate widget.
QStyle::SH_TabBar_CloseButtonPosition93Determines the position of the close button on a tab in a tab bar.
QStyle::SH_DockWidget_ButtonsHaveFrame94Determines if dockwidget buttons should have frames. Default is true.
QStyle::SH_ToolButtonStyle95Determines the default system style for tool buttons that uses Qt::ToolButtonFollowStyle.
QStyle::SH_RequestSoftwareInputPanel96Determines when a software input panel should be requested by input widgets. Returns an enum of type QStyle::RequestSoftwareInputPanel.
QStyle::SH_ScrollBar_Transient97Determines if the style supports transient scroll bars. Transient scroll bars appear when the content is scrolled and disappear when they are no longer needed.
QStyle::SH_Menu_SupportsSections98Determines if the style displays sections in menus or treat them as plain separators. Sections are separators with a text and icon hint.
QStyle::SH_ToolTip_WakeUpDelay99Determines the delay before a tooltip is shown, in milliseconds.
QStyle::SH_ToolTip_FallAsleepDelay100Determines the delay (in milliseconds) before a new wake time is needed when a tooltip is shown (notice: shown, not hidden). When a new wake isn’t needed, a user-requested tooltip will be shown nearly instantly.
QStyle::SH_Widget_Animate101Deprecated. Use SH_Widget_Animation_Duration instead.
QStyle::SH_Splitter_OpaqueResize102Determines if widgets are resized dynamically (opaquely) while interactively moving the splitter. This enum value was introduced in Qt 5.2.
QStyle::SH_TabBar_ChangeCurrentDelay105Determines the delay before the current tab is changed while dragging over the tabbar, in milliseconds. This enum value has been introduced in Qt 5.4
QStyle::SH_ItemView_ScrollMode112The default vertical and horizontal scroll mode as specified by the style. Can be overridden with QAbstractItemView::setVerticalScrollMode() and QAbstractItemView::setHorizontalScrollMode(). This enum value has been introduced in Qt 5.7.
QStyle::SH_TitleBar_ShowToolTipsOnButtons113Determines if tool tips are shown on window title bar buttons. The Mac style, for example, sets this to false. This enum value has been introduced in Qt 5.10.
QStyle::SH_Widget_Animation_Duration114Determines how much an animation should last (in ms). A value equal to zero means that the animations will be disabled. This enum value has been introduced in Qt 5.10.
QStyle::SH_ComboBox_AllowWheelScrolling115Determines if the mouse wheel can be used to scroll inside a QComboBox. This is on by default in all styles except the Mac style. This enum value has been introduced in Qt 5.10.
QStyle::SH_SpinBox_ButtonsInsideFrame116Determines if the spin box buttons are inside the line edit frame. This enum value has been introduced in Qt 5.11.
QStyle::SH_SpinBox_StepModifier117Determines which Qt::KeyboardModifier increases the step rate of QAbstractSpinBox. Possible values are Qt::NoModifier, Qt::ControlModifier (default) or Qt::ShiftModifier. Qt::NoModifier disables this feature. This enum value has been introduced in Qt 5.12.

可以看看styleHint().

10. enum QStyle::SubControl

enum QStyle::SubControl
flags QStyle::SubControls

这个枚举类型描述了可用的子控件枚举类型。子控件是复合控件(ComplexControl)中的控件元素。

ConstantValueDescription
QStyle::SC_None0x00000000Special value that matches no other sub control.
QStyle::SC_ScrollBarAddLine0x00000001Scroll bar add line (i.e., down/right arrow); see also QScrollBar.
QStyle::SC_ScrollBarSubLine0x00000002Scroll bar sub line (i.e., up/left arrow).
QStyle::SC_ScrollBarAddPage0x00000004Scroll bar add page (i.e., page down).
QStyle::SC_ScrollBarSubPage0x00000008Scroll bar sub page (i.e., page up).
QStyle::SC_ScrollBarFirst0x00000010Scroll bar first line (i.e., home).
QStyle::SC_ScrollBarLast0x00000020Scroll bar last line (i.e., end).
QStyle::SC_ScrollBarSlider0x00000040Scroll bar slider handle.
QStyle::SC_ScrollBarGroove0x00000080Special sub-control which contains the area in which the slider handle may move.
QStyle::SC_SpinBoxUp0x00000001Spin widget up/increase; see also QSpinBox.
QStyle::SC_SpinBoxDown0x00000002Spin widget down/decrease.
QStyle::SC_SpinBoxFrame0x00000004Spin widget frame.
QStyle::SC_SpinBoxEditField0x00000008Spin widget edit field.
QStyle::SC_ComboBoxEditField0x00000002Combobox edit field; see also QComboBox.
QStyle::SC_ComboBoxArrow0x00000004Combobox arrow button.
QStyle::SC_ComboBoxFrame0x00000001Combobox frame.
QStyle::SC_ComboBoxListBoxPopup0x00000008The reference rectangle for the combobox popup. Used to calculate the position of the popup.
QStyle::SC_SliderGroove0x00000001Special sub-control which contains the area in which the slider handle may move.
QStyle::SC_SliderHandle0x00000002Slider handle.
QStyle::SC_SliderTickmarks0x00000004Slider tickmarks.
QStyle::SC_ToolButton0x00000001Tool button (see also QToolButton).
QStyle::SC_ToolButtonMenu0x00000002Sub-control for opening a popup menu in a tool button.
QStyle::SC_TitleBarSysMenu0x00000001System menu button (i.e., restore, close, etc.).
QStyle::SC_TitleBarMinButton0x00000002Minimize button.
QStyle::SC_TitleBarMaxButton0x00000004Maximize button.
QStyle::SC_TitleBarCloseButton0x00000008Close button.
QStyle::SC_TitleBarLabel0x00000100Window title label.
QStyle::SC_TitleBarNormalButton0x00000010Normal (restore) button.
QStyle::SC_TitleBarShadeButton0x00000020Shade button.
QStyle::SC_TitleBarUnshadeButton0x00000040Unshade button.
QStyle::SC_TitleBarContextHelpButton0x00000080Context Help button.
QStyle::SC_DialHandle0x00000002The handle of the dial (i.e. what you use to control the dial).
QStyle::SC_DialGroove0x00000001The groove for the dial.
QStyle::SC_DialTickmarks0x00000004The tickmarks for the dial.
QStyle::SC_GroupBoxFrame0x00000008The frame of a group box.
QStyle::SC_GroupBoxLabel0x00000002The title of a group box.
QStyle::SC_GroupBoxCheckBox0x00000001The optional check box of a group box.
QStyle::SC_GroupBoxContents0x00000004The group box contents.
QStyle::SC_MdiNormalButton0x00000002The normal button for a MDI subwindow in the menu bar.
QStyle::SC_MdiMinButton0x00000001The minimize button for a MDI subwindow in the menu bar.
QStyle::SC_MdiCloseButton0x00000004The close button for a MDI subwindow in the menu bar.
QStyle::SC_All0xffffffffSpecial value that matches all sub-controls.

SubControls类型是 QFlags<SubControl>的typedef,存储了 SubControl值的OR运算集合。

可以看看 ComplexControl

11. enum QStyle::SubElement

这个枚举表示了一个小部件的子区域。样式实现使用这些区域来绘制小部件的不同部分。

ConstantValueDescription
QStyle::SE_PushButtonContents0Area containing the label (icon with text or pixmap).
QStyle::SE_PushButtonFocusRect1Area for the focus rect (usually larger than the contents rect).
QStyle::SE_PushButtonLayoutItem38Area that counts for the parent layout.
QStyle::SE_PushButtonBevel57[since 5.15] Area used for the bevel of the button.
QStyle::SE_CheckBoxIndicator2Area for the state indicator (e.g., check mark).
QStyle::SE_CheckBoxContents3Area for the label (text or pixmap).
QStyle::SE_CheckBoxFocusRect4Area for the focus indicator.
QStyle::SE_CheckBoxClickRect5Clickable area, defaults to SE_CheckBoxFocusRect.
QStyle::SE_CheckBoxLayoutItem32Area that counts for the parent layout.
QStyle::SE_DateTimeEditLayoutItem34Area that counts for the parent layout.
QStyle::SE_RadioButtonIndicator6Area for the state indicator.
QStyle::SE_RadioButtonContents7Area for the label.
QStyle::SE_RadioButtonFocusRect8Area for the focus indicator.
QStyle::SE_RadioButtonClickRect9Clickable area, defaults to SE_RadioButtonFocusRect.
QStyle::SE_RadioButtonLayoutItem39Area that counts for the parent layout.
QStyle::SE_ComboBoxFocusRect10Area for the focus indicator.
QStyle::SE_SliderFocusRect11Area for the focus indicator.
QStyle::SE_SliderLayoutItem40Area that counts for the parent layout.
QStyle::SE_SpinBoxLayoutItem41Area that counts for the parent layout.
QStyle::SE_ProgressBarGroove12Area for the groove.
QStyle::SE_ProgressBarContents13Area for the progress indicator.
QStyle::SE_ProgressBarLabel14Area for the text label.
QStyle::SE_ProgressBarLayoutItem37Area that counts for the parent layout.
QStyle::SE_FrameContents27Area for a frame’s contents.
QStyle::SE_ShapedFrameContents52Area for a frame’s contents using the shape in QStyleOptionFrame; see QFrame
QStyle::SE_FrameLayoutItem43Area that counts for the parent layout.
QStyle::SE_HeaderArrow17Area for the sort indicator for a header.
QStyle::SE_HeaderLabel16Area for the label in a header.
QStyle::SE_LabelLayoutItemSE_DateTimeEditLayoutItem + 2Area that counts for the parent layout.
QStyle::SE_LineEditContents26Area for a line edit’s contents.
QStyle::SE_TabWidgetLeftCorner21Area for the left corner widget in a tab widget.
QStyle::SE_TabWidgetRightCorner22Area for the right corner widget in a tab widget.
QStyle::SE_TabWidgetTabBar18Area for the tab bar widget in a tab widget.
QStyle::SE_TabWidgetTabContents20Area for the contents of the tab widget.
QStyle::SE_TabWidgetTabPane19Area for the pane of a tab widget.
QStyle::SE_TabWidgetLayoutItem45Area that counts for the parent layout.
QStyle::SE_ToolBoxTabContents15Area for a toolbox tab’s icon and label.
QStyle::SE_ToolButtonLayoutItem42Area that counts for the parent layout.
QStyle::SE_ItemViewItemCheckIndicator23Area for a view item’s check mark.
QStyle::SE_TabBarTearIndicator24Deprecated. Use SE_TabBarTearIndicatorLeft instead.
QStyle::SE_TabBarTearIndicatorLeftSE_TabBarTearIndicatorArea for the tear indicator on the left side of a tab bar with scroll arrows.
QStyle::SE_TabBarTearIndicatorRight56Area for the tear indicator on the right side of a tab bar with scroll arrows.
QStyle::SE_TabBarScrollLeftButton54Area for the scroll left button on a tab bar with scroll buttons.
QStyle::SE_TabBarScrollRightButton55Area for the scroll right button on a tab bar with scroll buttons.
QStyle::SE_TreeViewDisclosureItem25Area for the actual disclosure item in a tree branch.
QStyle::SE_GroupBoxLayoutItem44Area that counts for the parent layout.
QStyle::SE_CustomBase0xf0000000Base value for custom sub-elements. Custom values must be greater than this value.
QStyle::SE_DockWidgetFloatButton29The float button of a dock widget.
QStyle::SE_DockWidgetTitleBarText30The text bounds of the dock widgets title.
QStyle::SE_DockWidgetCloseButton28The close button of a dock widget.
QStyle::SE_DockWidgetIcon31The icon of a dock widget.
QStyle::SE_ComboBoxLayoutItem33Area that counts for the parent layout.
QStyle::SE_ItemViewItemDecoration46Area for a view item’s decoration (icon).
QStyle::SE_ItemViewItemText47Area for a view item’s text.
QStyle::SE_ItemViewItemFocusRect48Area for a view item’s focus rect.
QStyle::SE_TabBarTabLeftButton49Area for a widget on the left side of a tab in a tab bar.
QStyle::SE_TabBarTabRightButton50Area for a widget on the right side of a tab in a tab bar.
QStyle::SE_TabBarTabText51Area for the text on a tab in a tab bar.
QStyle::SE_ToolBarHandle53Area for the handle of a tool bar.

可以看看subElementRect()

三、QStyle Member Function文档

1. alignedRect()

static QRect
QStyle::alignedRect (Qt::LayoutDirection direction,Qt::Alignment alignment,const QSize &size,const QRect &rectangle
);

返回一个指定大小的矩形,大小由size指定。
该矩形会根据指定的对齐方式alignment和方向direction与给定的矩形rectangle对齐。

2. combinedLayoutSpacing()

int
QStyle::combinedLayoutSpacing (QSizePolicy::ControlTypes controls1,QSizePolicy::ControlTypes controls2,Qt::Orientation orientation,QStyleOption *option = nullptr,QWidget *widget		 = nullptr
) const;

返回在布局中应该用于 controls1controls2 之间的间距。

  1. orientation 指定控件是并排布置还是垂直堆叠。
  2. option 参数可以用来传递有关父小部件的额外信息。
  3. widget 参数是可选的,如果 option 为 nullptr,也可以使用 widget 参数。
  4. controls1controls2 是一个或多个控件类型的(enum QSizePolicy::ControlType) OR 组合。

此函数由布局系统调用。仅当 PM_LayoutHorizontalSpacing PM_LayoutVerticalSpacing 返回负值时使用此函数。

此函数在 Qt 4.3 中引入。

可以看看layoutSpacing()

3. drawComplexControl()

void
QStyle::drawComplexControl (QStyle::ComplexControl control,const QStyleOptionComplex *option,QPainter *painter,const QWidget *widget = nullptr
) const;

使用所提供的painter和指定的option样式选项绘制给定的控件。
widget参数是可选的,可以在绘制控件时作为辅助使用。
option参数是指向QStyleOptionComplex对象的指针,可以使用 qstyleoption_cast()函数将其转换为正确的子类。

请注意,指定的option的rect成员必须是逻辑坐标。此函数的重新实现应使用visualRect()将逻辑坐标转换为屏幕坐标,然后调用drawPrimitive()drawControl()函数。

下表列出了复杂控件元素及其关联的样式选项子类。样式选项包含绘制控件所需的所有参数,包括QStyleOption::state(其中包含在绘制时使用的样式标志),。该表还描述了将给定的option转换为适当的子类时设置的标志。

Complex ControlQStyleOptionComplex SubclassStyle FlagRemark
CC_SpinBoxQStyleOptionSpinBoxState_EnabledSet if the spin box is enabled.
State_HasFocusSet if the spin box has input focus.
CC_ComboBoxQStyleOptionComboBoxState_EnabledSet if the combobox is enabled.
State_HasFocusSet if the combobox has input focus.
CC_ScrollBarQStyleOptionSliderState_EnabledSet if the scroll bar is enabled.
State_HasFocusSet if the scroll bar has input focus.
CC_SliderQStyleOptionSliderState_EnabledSet if the slider is enabled.
State_HasFocusSet if the slider has input focus.
CC_DialQStyleOptionSliderState_EnabledSet if the dial is enabled.
State_HasFocusSet if the dial has input focus.
CC_ToolButtonQStyleOptionToolButtonState_EnabledSet if the tool button is enabled.
State_HasFocusSet if the tool button has input focus.
State_DownArrowSet if the tool button is down (i.e., a mouse button or the space bar is pressed).
State_OnSet if the tool button is a toggle button and is toggled on.
State_AutoRaiseSet if the tool button has auto-raise enabled.
State_RaisedSet if the button is not down, not on, and doesn’t contain the mouse when auto-raise is enabled.
CC_TitleBarQStyleOptionTitleBarState_EnabledSet if the title bar is enabled.

可以看看 drawPrimitive() and drawControl().

4. drawControl()

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

使用所提供的painter和指定的option样式选项绘制给定的元素。
widget参数是可选的,可以在绘制控件时作为辅助使用。
option参数是指向QStyleOption对象的指针,可以使用qstyleoption_cast()函数将其转换为正确的子类。

下表列出了控件元素及其关联的样式选项子类。样式选项包含绘制控件所需的所有参数,包括QStyleOption::state(其中包含在绘制时使用的样式标志)。该表还描述了将给定的option转换为适当的子类时设置的标志。

请注意,如果某个控件元素未在此列出,则是因为它使用的是普通的QStyleOption对象。

Control ElementQStyleOption SubclassStyle FlagRemark
CE_MenuItem, CE_MenuBarItemQStyleOptionMenuItemState_SelectedThe menu item is currently selected item.
State_EnabledThe item is enabled.
State_DownArrowIndicates that a scroll down arrow should be drawn.
State_UpArrowIndicates that a scroll up arrow should be drawn
State_HasFocusSet if the menu bar has input focus.
CE_PushButton, CE_PushButtonBevel, CE_PushButtonLabelQStyleOptionButtonState_EnabledSet if the button is enabled.
State_HasFocusSet if the button has input focus.
State_RaisedSet if the button is not down, not on and not flat.
State_OnSet if the button is a toggle button and is toggled on.
State_SunkenSet if the button is down (i.e., the mouse button or the space bar is pressed on the button).
CE_RadioButton, CE_RadioButtonLabel, CE_CheckBox, CE_CheckBoxLabelQStyleOptionButtonState_EnabledSet if the button is enabled.
State_HasFocusSet if the button has input focus.
State_OnSet if the button is checked.
State_OffSet if the button is not checked.
State_NoChangeSet if the button is in the NoChange state.
State_SunkenSet if the button is down (i.e., the mouse button or the space bar is pressed on the button).
CE_ProgressBarContents, CE_ProgressBarLabel, CE_ProgressBarGrooveQStyleOptionProgressBarState_EnabledSet if the progress bar is enabled.
State_HasFocusSet if the progress bar has input focus.
CE_Header, CE_HeaderSection, CE_HeaderLabelQStyleOptionHeader
CE_TabBarTab, CE_TabBarTabShape, CE_TabBarTabLabelQStyleOptionTabState_EnabledSet if the tab bar is enabled.
State_SelectedThe tab bar is the currently selected tab bar.
State_HasFocusSet if the tab bar tab has input focus.
CE_ToolButtonLabelQStyleOptionToolButtonState_EnabledSet if the tool button is enabled.
State_HasFocusSet if the tool button has input focus.
State_SunkenSet if the tool button is down (i.e., a mouse button or the space bar is pressed).
State_OnSet if the tool button is a toggle button and is toggled on.
State_AutoRaiseSet if the tool button has auto-raise enabled.
State_MouseOverSet if the mouse pointer is over the tool button.
State_RaisedSet if the button is not down and is not on.
CE_ToolBoxTabQStyleOptionToolBoxState_SelectedThe tab is the currently selected tab.
CE_HeaderSectionQStyleOptionHeaderState_SunkenIndicates that the section is pressed.
State_UpArrowIndicates that the sort indicator should be pointing up.
State_DownArrowIndicates that the sort indicator should be pointing down.

可以看看 drawPrimitive() and drawComplexControl().

5. drawItemPixmap()

virtual void
QStyle::drawItemPixmap (QPainter *painter,const QRect &rectangle,int alignment,const QPixmap &pixmap
) const;

使用所提供的painter,根据指定的alignment,在指定的rectangle中绘制给定的pixmap。

另请参见drawItemText()。

6. drawItemText()

virtual void
QStyle::drawItemText (QPainter *painter,const QRect &rectangle,int alignment,const QPalette &palette,bool enabled,const QString &text,QPalette::ColorRole textRole = QPalette::NoRole
) const;

在指定的矩形内使用提供的painter和调色板(palette)绘制给定的文本。

  1. 文本使用painter的笔绘制,并根据指定的对齐方式进行对齐和换行。
  2. 如果指定了明确的文本角色(textRole),则使用调色板中该角色的颜色绘制文本。
  3. 启用参数(enabled)表示项目是否启用;在重新实现此函数时,启用参数应影响项目的绘制方式。

7. drawPrimitive()

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

使用提供的painter和指定的样式选项(option)绘制给定的基本元素(primitive element)。

widget参数是可选的,可能持有一个在绘制基本元素时有帮助的窗口部件。

下表列出了基本元素(primitive element)及其相关的样式选项子类。样式选项(option)包含绘制元素所需的所有参数,包括 QStyleOption::state,它包含在绘制时使用的样式标志。表格还描述了当将给定的选项转换为适当的子类时设置了哪些标志。

请注意,如果基本元素未在此处列出,则是因为它使用的是普通的 QStyleOption 对象。

Primitive ElementQStyleOption SubclassStyle FlagRemark
PE_FrameFocusRectQStyleOptionFocusRectState_FocusAtBorderWhether the focus is is at the border or inside the widget.
PE_IndicatorCheckBoxQStyleOptionButtonState_NoChangeIndicates a "tri-state" checkbox.
State_OnIndicates the indicator is checked.
PE_IndicatorRadioButtonQStyleOptionButtonState_OnIndicates that a radio button is selected.
State_NoChangeIndicates a "tri-state" controller.
State_EnabledIndicates the controller is enabled.
PE_IndicatorBranchQStyleOptionState_ChildrenIndicates that the control for expanding the tree to show child items, should be drawn.
State_ItemIndicates that a horizontal branch (to show a child item), should be drawn.
State_OpenIndicates that the tree branch is expanded.
State_SiblingIndicates that a vertical line (to show a sibling item), should be drawn.
PE_IndicatorHeaderArrowQStyleOptionHeaderState_UpArrowIndicates that the arrow should be drawn up; otherwise it should be down.
PE_FrameGroupBox, PE_Frame, PE_FrameLineEdit, PE_FrameMenu, PE_FrameDockWidget, PE_FrameWindowQStyleOptionFrameState_SunkenIndicates that the Frame should be sunken.
PE_IndicatorToolBarHandleQStyleOptionState_HorizontalIndicates that the window handle is horizontal instead of vertical.
PE_IndicatorSpinPlus, PE_IndicatorSpinMinus, PE_IndicatorSpinUp, PE_IndicatorSpinDown,QStyleOptionSpinBoxState_SunkenIndicates that the button is pressed.
PE_PanelButtonCommandQStyleOptionButtonState_EnabledSet if the button is enabled.
State_HasFocusSet if the button has input focus.
State_RaisedSet if the button is not down, not on and not flat.
State_OnSet if the button is a toggle button and is toggled on.
State_SunkenSet if the button is down (i.e., the mouse button or the space bar is pressed on the button).

另请参考 drawComplexControl() and drawControl().

8. generatedIconPixmap()

virtual QPixmap
generatedIconPixmap (QIcon::Mode iconMode,const QPixmap &pixmap, const QStyleOption *option
) const = 0;

返回给定图像(pixmap)的副本,该副本经过样式化以符合指定的图标模式(iconMode),并考虑由option指定的调色板(palette)。

option参数可以传递额外的信息,但它必须包含一个调色板。

请注意,并非所有的图像都会符合这种样式化,在这种情况下,返回的图像是一个普通的副本。

另请参见 QIcon

9. hitTestComplexControl()

virtual QStyle::SubControl
hitTestComplexControl (QStyle::ComplexControl control,const QStyleOptionComplex *option,const QPoint &position,const QWidget *widget = nullptr
) const =0;

返回给定复杂控件(complex control)中指定位置(position)的子控件,使用由option指定的样式选项。

请注意,位置是以屏幕坐标表示的。

option参数是一个指向QStyleOptionComplex对象(或其子类之一)的指针。可以使用qstyleoption_cast()函数将对象转换为适当的类型。详情请参见drawComplexControl()

widget参数是可选的,可以为该函数提供额外的信息。

另请参见 drawComplexControl() and subControlRect().

10. itemPixmapRect()

virtual QRect
itemPixmapRect (const QRect &rectangle, int alignment,const QPixmap &pixmap
) const;

返回在给定矩形内根据定义的对齐方式绘制指定图像(pixmap)的矩形区域。

11. itemTextRect()

virtual QRect
itemTextRect (const QFontMetrics &metrics,const QRect &rectangle,int alignment, bool enabled, const QString &text
) const;

返回在给定矩形内根据指定的字体度量(font metrics)和对齐方式绘制提供的文本(text)的区域。

enabled参数表示相关项目是否启用。

如果给定的矩形大于渲染文本所需的区域,则返回的矩形将根据指定的对齐方式在矩形内偏移。例如,如果对齐方式是Qt::AlignCenter,返回的矩形将在矩形内居中。

如果给定的矩形小于所需的区域,返回的矩形将是足够渲染文本的最小矩形。

12. layoutSpacing()

virtual int
QStyle::layoutSpacing (QSizePolicy::ControlType control1,QSizePolicy::ControlType control2,Qt::Orientation orientation,const QStyleOption *option = nullptr,const QWidget *widget	   = nullptr
) const = 0;

返回在布局中控制项control1和control2之间应使用的间距。

orientation指定控件是并排布置还是垂直堆叠。

option参数可以用于传递有关父窗口部件的额外信息。如果option为nullptr,也可以使用widget参数。

此函数由布局系统调用。仅当PM_LayoutHorizontalSpacingPM_LayoutVerticalSpacing返回负值时才使用此函数。

此函数在Qt 4.3中引入。

另请参见 combinedLayoutSpacing().

13. pixelMetric()

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

返回给定像素度量(pixel metric)的值。

指定的optionwidget可以用于计算该度量。一般来说,widget参数不使用。可以使用qstyleoption_cast()函数将option转换为适当的类型。

请注意,即使对于可以使用的PixelMetricsoption也可能为零。请参见下表了解适当的option转换:

Pixel MetricQStyleOption Subclass
PM_SliderControlThicknessQStyleOptionSlider
PM_SliderLengthQStyleOptionSlider
PM_SliderTickmarkOffsetQStyleOptionSlider
PM_SliderSpaceAvailableQStyleOptionSlider
PM_ScrollBarExtentQStyleOptionSlider
PM_TabBarTabOverlapQStyleOptionTab
PM_TabBarTabHSpaceQStyleOptionTab
PM_TabBarTabVSpaceQStyleOptionTab
PM_TabBarBaseHeightQStyleOptionTab
PM_TabBarBaseOverlapQStyleOptionTab

一些pixel metrics是从widgets调用的,而有些则仅由样式内部调用。如果metric不是由一个widget调用的,是否使用它由样式作者自行决定。对于某些样式,可能不适合使用这个方法。

14. polish()

virtual void polish (QWidget *widget);

初始化给定窗口部件(widget)的外观。

此函数在每个窗口部件完全创建之后但在首次显示之前的某个时间点被调用。

请注意,默认实现不执行任何操作。在此函数中合理的操作可能是调用QWidget::setBackgroundMode()函数来设置widget的背景模式。不要使用此函数来设置例如几何形状。重新实现此函数提供了一种更改窗口部件外观的后门,但由于Qt的样式引擎,通常不需要实现此函数;而是重新实现drawItemPixmap()drawItemText()drawPrimitive()等函数。

QWidget::inherits()函数可能提供足够的信息来允许特定类的自定义。但是,由于新的QStyle子类预计会与所有当前和未来的窗口部件合理地配合使用,建议有限地使用硬编码的自定义。

另请参见unpolish()

重载版本
virtual void polish(QApplication *application);

延迟初始化给定的应用程序对象。

virtual void polish(QPalette &palette);

根据调色板的特定样式要求(如果有)更改调色板(palette)。

15. proxy()

const QStyle *QStyle::proxy() const;

此函数返回该样式的当前代理。默认情况下,大多数样式将返回它们自己。然而,当使用代理样式时,它将允许样式回调到其代理。

16. sizeFromContents()

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

返回由指定的optiontype描述的元素的大小,基于提供的contentsSize

option参数是指向QStyleOption或其子类之一的指针。可以使用qstyleoption_cast()函数将option转换为适当的类型。

widget是一个可选参数,可以包含用于计算大小的额外信息。
请参见下表了解适当的option转换:

Contents TypeQStyleOption Subclass
CT_CheckBoxQStyleOptionButton
CT_ComboBoxQStyleOptionComboBox
CT_GroupBoxQStyleOptionGroupBox
CT_HeaderSectionQStyleOptionHeader
CT_ItemViewItemQStyleOptionViewItem
CT_LineEditQStyleOptionFrame
CT_MdiControlsQStyleOptionComplex
CT_MenuQStyleOption
CT_MenuItemQStyleOptionMenuItem
CT_MenuBarQStyleOptionMenuItem
CT_MenuBarItemQStyleOptionMenuItem
CT_ProgressBarQStyleOptionProgressBar
CT_PushButtonQStyleOptionButton
CT_RadioButtonQStyleOptionButton
CT_ScrollBarQStyleOptionSlider
CT_SizeGripQStyleOption
CT_SliderQStyleOptionSlider
CT_SpinBoxQStyleOptionSpinBox
CT_SplitterQStyleOption
CT_TabBarTabQStyleOptionTab
CT_TabWidgetQStyleOptionTabWidgetFrame
CT_ToolButtonQStyleOptionToolButton

另请参见 ContentsType and QStyleOption.

16. sliderPositionFromValue()

static int
sliderPositionFromValue (int min, int max, int logicalValue,int span, bool upsideDown = false
);

将给定的逻辑值(logicalValue)转换为像素位置。
min参数映射到0,max参数映射到span,其他值在两者之间均匀分布。

此函数可以处理整个整数范围而不会溢出,前提是span小于4096。

默认情况下,此函数假定最大值位于水平项的右侧和垂直项的底部。将upsideDown参数设置为true以反转此行为。

另请参见 sliderValueFromPosition()。

17. sliderValueFromPosition()
static int
sliderValueFromPosition(int min,int max,int position, int span, bool upsideDown = false
);

将给定的像素位置转换为逻辑值。0 映射到 min 参数,span 映射到 max,其他值则在两者之间均匀分布。

此函数可以处理整个整数范围而不会发生溢出。

默认情况下,此函数假设最大值位于水平项目的右侧和垂直项目的底部。将 upsideDown 参数设置为 true 可逆转此行为。

另请参见 sliderPositionFromValue()。

18. standardIcon()

virtual QIcon
standardIcon (QStyle::StandardPixmap standardIcon, const QStyleOption *option = 0,const QWidget *widget = 0
)const =0;

返回给定标准图标(standardIcon)的图标。

standardIcon是一个标准图像,可以遵循某些现有的GUI样式或指南。

option参数可以用于传递定义适当图标时所需的额外信息。

widget参数是可选的,也可以用于帮助确定图标。

此函数在Qt 4.1中引入。

19. standardPalette()

virtual QPalette standardPalette() const;

返回样式的标准调色板。

请注意,在支持系统颜色的系统上,不使用样式的标准调色板。特别是,Windows Vista和Mac样式不使用标准调色板,而是使用本地主题引擎。在这些样式中,不应使用QApplication::setPalette()设置调色板。

另请参见QApplication::setPalette()

20. styleHint()

virtual int
styleHint (QStyle::StyleHint hint,const QStyleOption *option	 = nullptr,const QWidget *widget		 = nullptr,QStyleHintReturn *returnData = nullptr
) const = 0;

返回一个整数,表示由提供的样式选项描述的给定窗口部件的指定样式提示(style hint)。

当查询窗口部件需要比styleHint()返回的整数更详细的数据时,使用returnData。有关详细信息,请参阅QStyleHintReturn类描述。

21. subControlRect()

virtual QRect
subControlRect (QStyle::ComplexControl control,const QStyleOptionComplex *option,QStyle::SubControl subControl,const QWidget *widget = nullptr
) const = 0;

返回包含给定复杂控件(complex control)的指定子控件(subControl)的矩形(使用由option指定的样式)。该矩形以屏幕坐标定义。

option参数是指向QStyleOptionComplex或其子类之一的指针,可以使用qstyleoption_cast()函数将其转换为适当的类型。详情请参见drawComplexControl()

widget参数是可选的,可以为该函数提供额外的信息。

另请参见drawComplexControl()。

22. subElementRect()

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

返回给定元素(element)的子区域,如提供的样式选项(style option)中所描述。返回的矩形以屏幕坐标定义。

widget参数是可选的,可以用于帮助确定区域。可以使用qstyleoption_cast()函数将QStyleOption对象转换为适当的类型。
请参见下表了解适当的option转换:

Sub ElementQStyleOption Subclass
SE_PushButtonContentsQStyleOptionButton
SE_PushButtonFocusRectQStyleOptionButton
SE_PushButtonBevelQStyleOptionButton
SE_CheckBoxIndicatorQStyleOptionButton
SE_CheckBoxContentsQStyleOptionButton
SE_CheckBoxFocusRectQStyleOptionButton
SE_RadioButtonIndicatorQStyleOptionButton
SE_RadioButtonContentsQStyleOptionButton
SE_RadioButtonFocusRectQStyleOptionButton
SE_ComboBoxFocusRectQStyleOptionComboBox
SE_ProgressBarGrooveQStyleOptionProgressBar
SE_ProgressBarContentsQStyleOptionProgressBar
SE_ProgressBarLabelQStyleOptionProgressBar

23. unpolish()

virtual void unpolish(QWidget *widget);

取消初始化给定窗口部件的外观。

此函数是polish()的对立面。每当样式动态更改时,它会为每个已初始化的窗口部件调用;之前的样式必须取消其设置,然后新样式才能再次初始化它们

请注意,unpolish()只有在窗口部件被销毁时才会被调用。这在某些情况下可能会导致问题,例如,如果你从UI中移除一个窗口部件,将其缓存,然后在样式更改后重新插入它;Qt的一些类会缓存它们的窗口部件。

另请参见polish()。

重载版本
virtual void unpolish(QApplication *application);

取消对给定的应用程序的初始化。

24. visualAlignment()

static Qt::Alignment
visualAlignment (Qt::LayoutDirection direction, Qt::Alignment alignment
);

根据布局方向,将不带Qt::AlignAbsoluteQt::AlignLeftQt::AlignRight对齐方式转换为带Qt::AlignAbsoluteQt::AlignLeftQt::AlignRight对齐方式。其他对齐标志保持不变。

如果未指定水平对齐方式,该函数将返回给定布局方向的默认对齐方式。

另请参见 QWidget::layoutDirection

25. visualPos()

static QPoint
visualPos (Qt::LayoutDirection direction, const QRect &boundingRectangle, const QPoint &logicalPosition
);

根据指定方向(direction),返回将给定的逻辑位置(logicalPosition)转换为屏幕坐标后的结果。转换时使用boundingRectangle

另请参见QWidget::layoutDirection。

26. visualRect()

virtual QRect
visualRect (Qt::LayoutDirection direction,const QRect &boundingRectangle,const QRect &logicalRectangle
);

根据指定方向(direction),返回将给定的逻辑矩形(logicalRectangle)转换为屏幕坐标后的结果。转换时使用boundingRectangle

提供此函数是为了支持从右到左的桌面,通常在实现subControlRect()函数时使用。

另请参见QWidget::layoutDirection。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1553129.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

OpenGL笔记之事件驱动设计将相机控制类和应用程序类分离

OpenGL笔记之事件驱动设计将相机控制类和应用程序类分离 —— 2024-10-02 下午 code review! 文章目录 OpenGL笔记之事件驱动设计将相机控制类和应用程序类分离1.代码图片2.分析3.UML4.代码 1.代码图片 运行 Mouse button 1 pressed at (100, 200) Mouse dragged by (50, 50)…

Spring(学习笔记)

<context:annotation-config/>是 Spring 配置文件中的一个标签&#xff0c;用于开启注解配置功能。这个标签可以让 Spring 容器识别并处理使用注解定义的 bean。例如&#xff0c;可以使用 Autowired 注解自动装配 bean&#xff0c;或者使用 Component 注解将类标记为 bea…

10/02赛后总结

T1学习除法 题目传送门&#xff1a;学习除法http://bbcoj.cn/contest/1028/problem/1 说白了&#xff0c;就是检验是不是质数罢了&#xff0c;是质数输出0&#xff0c;不然输出1&#xff1b; 但是质数判断写错了 100分只有60分&#xff0c;damn #include<bits/stdc.h>…

【Linux】进程间关系与守护进程

超出能力之外的事&#xff0c; 如果永远不去做&#xff0c; 那你就永远无法进步。 --- 乌龟大师 《功夫熊猫》--- 进程间关系与守护进程 1 进程组2 会话3 控制终端4 作业控制5 守护进程 1 进程组 之前我们提到了进程的概念&#xff0c; 其实每一个进程除了有一个进程 ID(P…

Django5 使用pyinstaller打包成 exe服务

首先&#xff1a;确保当前的django项目可以完美运行&#xff0c;再进行后续操作 python manage.py runserver第一步 安装 pyinstaller pip install pyinstaller第二步 创建spec 文件 pyinstaller --name manage --onefile manage.pypyinstaller&#xff1a;这是调用 PyInsta…

数据异质性与数据异构性的本质和举例说明

&#x1f349; CSDN 叶庭云&#xff1a;https://yetingyun.blog.csdn.net/ 在现代数据科学与信息技术领域&#xff0c;“数据异质性” 与 “数据异构性” 是两个常见的概念。对于初学者而言&#xff0c;明确这两个概念的本质及其间的差异至关重要。本文旨在以简明易懂的方式&am…

Python笔记 - 利用装饰器设计注解体系

认识注解 注解&#xff08;Annotation&#xff09;是一种用于为代码添加元数据的机制。这些元数据可以在运行时被访问&#xff0c;用于为代码元素&#xff08;如类、方法、字段等&#xff09;提供额外的信息或指示。 由于Python中装饰器只能装饰类和方法&#xff0c;因此也只…

Mac 网络连接正常,微信可以使用,但浏览器打不开网页?

解决&#xff1a; Step1&#xff0c;选择&#x1f34e;图标&#xff0c;选择系统设置&#xff08;或系统偏好设置&#xff09;打开&#xff1b; Step2&#xff0c;选择网络&#xff0c;Wi-Fi Step3&#xff0c;选择详细信息&#xff1b; Step4: 选择代理&#xff0c;关闭右…

3.点位管理改造-列表查询——帝可得管理系统

目录 前言一、与页面原型差距1.现在&#xff1a;2.目标&#xff1a;3. 存在问题&#xff1a;所在区域和合作商ID展示的都是ID&#xff0c;而不是名称&#xff1b;同时合作商ID应改为合作商 二、修改1.重新设计SQL语句2.修改mapper层&#xff0c;使用Mybatis中的嵌套查询3.修改s…

C. Tree Pruning【Codeforces Round 975 (Div. 1)】

C. Tree Pruning (永远不知道为什么TLE直到把初始化的memset换成for循环 题意很简单&#xff0c;就是找到一个深度&#xff0c;使得删除最少的节点且所有的叶子节点都为这个深度。 从小到大遍历可能的深度i&#xff0c;容易知道所有 深度大于i的节点 和所有 子树最大深度小于i…

操作符详解与表达式求值

目录 操作符分类 1.算数操作符 2.移位操作符&#xff08;只适用于整数范围&#xff09; &#xff08;1&#xff09;引入 &#xff08;2&#xff09;左移操作符<< &#xff08;2&#xff09;右移操作符>> 3.位操作符 4.赋值操作符 复合赋值符 5.单目操作符 5…

深度优先搜索(DFS)与有向图中的唯一结点

深度优先搜索(DFS)与有向图中的唯一结点 前提与定义分析与方法伪代码与 C 代码实现解释结果在图论中,深度优先搜索(DFS)是一种用于遍历或搜索图的算法。DFS 从给定的起始结点出发,沿着图的深度方向尽可能深地搜索,直到无法继续为止,然后回溯并从未访问过的邻接结点继续…

Unraid的cache使用btrfs或zfs?

Unraid的cache使用btrfs或zfs&#xff1f; 背景&#xff1a;由于在unraid中添加了多个docker和虚拟机&#xff0c;因此会一直访问硬盘。然而&#xff0c;单个硬盘实在难以让人放心。在阵列盘中&#xff0c;可以通过添加校验盘进行数据保护&#xff0c;在cache中无法使用xfs格式…

YOLOv11改进 | Neck篇 | YOLOv11引入Slim-Neck(轻量)

1. Slim-Neck介绍 摘要&#xff1a;目标检测是计算机视觉中重要的下游任务。 对于车载边缘计算平台来说&#xff0c;巨大的模型很难达到实时检测的要求。 而且&#xff0c;由大量深度可分离卷积层构建的轻量级模型无法达到足够的精度。 我们引入了一种新的轻量级卷积技术 GSCon…

【顺序查找】

目录 一. 顺序查找的概念二. 查找的性能计算 \quad 一. 顺序查找的概念 \quad \quad 二. 查找的性能计算 \quad

使用ROCm的GPU感知MPI

GPU-aware MPI with ROCm — ROCm Blogs (amd.com) 注意: 此博客之前是 AMD Lab Notes博客系列的一部分。 MPI&#xff08;消息传递接口&#xff09;是高性能计算中进程间通信的事实标准。MPI进程在其本地数据上进行计算&#xff0c;同时进行大量的相互通信。这使得MPI程序可以…

【折半查找】

目录 一. 折半查找的概念二. 折半查找的过程三. 折半查找的代码实现四. 折半查找的性能分析 \quad 一. 折半查找的概念 \quad 必须有序 \quad 二. 折半查找的过程 \quad \quad 三. 折半查找的代码实现 \quad 背下来 \quad 四. 折半查找的性能分析 \quad 记住 比较的是层数 …

sed引入变量中的坑

sed引入变量问题 1、sed引入变量2、sed引入变量问题 1、sed引入变量 sed指令引入变量&#xff0c;直接使用双引号即可 例如&#xff0c;下面的示例&#xff1a; ab; echo "abc" | sed "s/b/$a/g"2、sed引入变量问题 但是&#xff0c;如果变量值中带有/等…

自闭症寄宿学校:释放孩子内心的美

在自闭症儿童的成长旅程中&#xff0c;寻找一个既能提供专业康复服务&#xff0c;又能让孩子感受到爱与关怀的教育环境&#xff0c;是许多家庭梦寐以求的目标。在广州&#xff0c;星贝育园自闭症儿童寄宿制学校正是这样一所充满爱与希望的学校&#xff0c;它不仅为自闭症儿童提…

CMU 10423 Generative AI:lec13/13.5(text-to-image models:三大类方法、评估标准、图像编辑原理)

1 文章目录 1 lec13和lec13.5概述2 Text-to-Image Generation 概念、主要方法、挑战、发展历程1. **基本概念**2. **主要技术方法**2.1. **生成对抗网络&#xff08;GAN&#xff09;**2.2. **自回归模型&#xff08;Autoregressive Models&#xff09;**2.3. **扩散模型&#x…