前言
本文翻译自Qt官方文档,详细介绍了各成员/类型的作用,包含部分示例代码。
QStyle类的内容非常庞大,如需快速了解类成员和使用简介,请参见 QStyle简介。
一、QStyle Class
QStyle
是一个抽象基类,封装了GUI的外观。
Qt包含一组QStyle
子类,这些子类模拟了Qt支持的不同平台的样式(QWindowStyle
、QMacStyle
等)。默认情况下,这些样式内置在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绘图函数需要四个参数:
- 一个枚举值。
- 用于指定要绘制的图形元素。
- 一个
QStyleOption
- 指定如何、在何处渲染元素。
- 一个
QPainter
- 用于绘制元素。
- 一个
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);
}
QStyle
从QStyleOption
获取渲染图形元素所需的所有信息。widget
作为最后一个参数传递,以防样式需要它来执行特殊效果(例如macOS上的动画默认按钮),但这不是强制的。实际上,通过正确设置QPainter
,您可以使用QStyle
在任何绘图设备上绘图,而不仅仅是小部件。
QStyleOption
有各种各样的子类,用于不同类型的可绘制图形元素。例如,PE_FrameFocusRec
t需要一个QStyleOptionFocusRect
参数。
为了确保绘图操作尽可能快,
QStyleOption
及其子类具有公共数据成员。有关如何使用它的详细信息,请参阅QStyleOption
类文档。
为了方便起见,Qt提供了QStylePainter
类,它结合了QStyle
、QPainter
和QWidget
。这使得编写以下代码成为可能:
QStylePainter painter(this);
...
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
而不是:
QPinter painter(this);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
3. 创建一个自定义Style
您可以创建自定义样式,来为您的应用程序创建自定义外观。
创建自定义样式有两种方法:
- 静态方法
- 可以选择现有的
QStyle
类,子类化它,并重新实现虚函数以提供自定义行为,或者从头开始创建整个QStyle
类。
- 可以选择现有的
- 动态方法
- 可以在运行时修改系统样式的行为。
下面描述了静态方法。
动态方法在
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_IndicatorSpinUp
和PE_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_SpinBoxDown
points[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
负责绘制项目的背景,并在QCommonStyle
的CE_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
此枚举描述了可用的复杂控件。复杂控件会因用户点击的位置或按下的键而表现不同行为。
Constant | Value | Description |
---|---|---|
QStyle::CC_SpinBox | 0 | A spinbox, like QSpinBox. |
QStyle::CC_ComboBox | 1 | A combobox, like QComboBox. |
QStyle::CC_ScrollBar | 2 | A scroll bar, like QScrollBar. |
QStyle::CC_Slider | 3 | A slider, like QSlider. |
QStyle::CC_ToolButton | 4 | A tool button, like QToolButton. |
QStyle::CC_TitleBar | 5 | A title bar, like those used in QMdiSubWindow. |
QStyle::CC_GroupBox | 7 | A group box, like QGroupBox. |
QStyle::CC_Dial | 6 | A dial, like QDial. |
QStyle::CC_MdiControls | 8 | The minimize, close, and normal button in the menu bar for a maximized MDI subwindow. |
QStyle::CC_CustomBase | 0xf0000000 | Base value for custom complex controls. Custom values must be greater than this value. |
可以看看 SubControl and drawComplexControl().
2. enum QStyle::ContentsType
enum QStyle::ContentsType
此枚举描述了可用的内容类型。这些内容类型用于计算各种小部件的内容大小。
Constant | Value | Description |
---|---|---|
QStyle::CT_CheckBox | 1 | A check box, like QCheckBox. |
QStyle::CT_ComboBox | 4 | A combo box, like QComboBox. |
QStyle::CT_HeaderSection | 19 | A header section, like QHeader. |
QStyle::CT_LineEdit | 14 | A line edit, like QLineEdit. |
QStyle::CT_Menu | 10 | A menu, like QMenu. |
QStyle::CT_MenuBar | 9 | A menu bar, like QMenuBar. |
QStyle::CT_MenuBarItem | 8 | A menu bar item, like the buttons in a QMenuBar. |
QStyle::CT_MenuItem | 7 | A menu item, like QMenuItem. |
QStyle::CT_ProgressBar | 6 | A progress bar, like QProgressBar. |
QStyle::CT_PushButton | 0 | A push button, like QPushButton. |
QStyle::CT_RadioButton | 2 | A radio button, like QRadioButton. |
QStyle::CT_SizeGrip | 16 | A size grip, like QSizeGrip. |
QStyle::CT_Slider | 12 | A slider, like QSlider. |
QStyle::CT_ScrollBar | 13 | A scroll bar, like QScrollBar. |
QStyle::CT_SpinBox | 15 | A spin box, like QSpinBox. |
QStyle::CT_Splitter | 5 | A splitter, like QSplitter. |
QStyle::CT_TabBarTab | 11 | A tab on a tab bar, like QTabBar. |
QStyle::CT_TabWidget | 17 | A tab widget, like QTabWidget. |
QStyle::CT_ToolButton | 3 | A tool button, like QToolButton. |
QStyle::CT_GroupBox | 20 | A group box, like QGroupBox. |
QStyle::CT_ItemViewItem | 22 | An item inside an item view. |
QStyle::CT_CustomBase | 0xf0000000 | Base value for custom contents types. Custom values must be greater than this value. |
QStyle::CT_MdiControls | 21 | The minimize, normal, and close button in the menu bar for a maximized MDI subwindow. |
可以看看 sizeFromContents()。
3. enum QStyle::ControlElement
enum QStyle::ControlElement
此枚举表示一个控件元素。控件元素是小部件的一部分,用于执行某些操作或向用户显示信息。
Constant | Value | Description |
---|---|---|
QStyle::CE_PushButton | 0 | A QPushButton, draws CE_PushButtonBevel, CE_PushButtonLabel and PE_FrameFocusRect. |
QStyle::CE_PushButtonBevel | 1 | The bevel and default indicator of a QPushButton. |
QStyle::CE_PushButtonLabel | 2 | The label (an icon with text or pixmap) of a QPushButton. |
QStyle::CE_DockWidgetTitle | 30 | Dock window title. |
QStyle::CE_Splitter | 28 | Splitter handle; see also QSplitter. |
QStyle::CE_CheckBox | 3 | A QCheckBox, draws a PE_IndicatorCheckBox, a CE_CheckBoxLabel and a PE_FrameFocusRect. |
QStyle::CE_CheckBoxLabel | 4 | The label (text or pixmap) of a QCheckBox. |
QStyle::CE_RadioButton | 5 | A QRadioButton, draws a PE_IndicatorRadioButton, a CE_RadioButtonLabel and a PE_FrameFocusRect. |
QStyle::CE_RadioButtonLabel | 6 | The label (text or pixmap) of a QRadioButton. |
QStyle::CE_TabBarTab | 7 | The tab and label within a QTabBar. |
QStyle::CE_TabBarTabShape | 8 | The tab shape within a tab bar. |
QStyle::CE_TabBarTabLabel | 9 | The label within a tab. |
QStyle::CE_ProgressBar | 10 | A QProgressBar, draws CE_ProgressBarGroove, CE_ProgressBarContents and CE_ProgressBarLabel. |
QStyle::CE_ProgressBarGroove | 11 | The groove where the progress indicator is drawn in a QProgressBar. |
QStyle::CE_ProgressBarContents | 12 | The progress indicator of a QProgressBar. |
QStyle::CE_ProgressBarLabel | 13 | The text label of a QProgressBar. |
QStyle::CE_ToolButtonLabel | 22 | A tool button’s label. |
QStyle::CE_MenuBarItem | 20 | A menu item in a QMenuBar. |
QStyle::CE_MenuBarEmptyArea | 21 | The empty area of a QMenuBar. |
QStyle::CE_MenuItem | 14 | A menu item in a QMenu. |
QStyle::CE_MenuScroller | 15 | Scrolling areas in a QMenu when the style supports scrolling. |
QStyle::CE_MenuTearoff | 18 | A menu item representing the tear off section of a QMenu. |
QStyle::CE_MenuEmptyArea | 19 | The area in a menu without menu items. |
QStyle::CE_MenuHMargin | 17 | The horizontal extra space on the left/right of a menu. |
QStyle::CE_MenuVMargin | 16 | The vertical extra space on the top/bottom of a menu. |
QStyle::CE_ToolBoxTab | 26 | The toolbox’s tab and label within a QToolBox. |
QStyle::CE_SizeGrip | 27 | Window resize handle; see also QSizeGrip. |
QStyle::CE_Header | 23 | A header. |
QStyle::CE_HeaderSection | 24 | A header section. |
QStyle::CE_HeaderLabel | 25 | The header’s label. |
QStyle::CE_ScrollBarAddLine | 31 | Scroll bar line increase indicator. (i.e., scroll down); see also QScrollBar. |
QStyle::CE_ScrollBarSubLine | 32 | Scroll bar line decrease indicator (i.e., scroll up). |
QStyle::CE_ScrollBarAddPage | 33 | Scolllbar page increase indicator (i.e., page down). |
QStyle::CE_ScrollBarSubPage | 34 | Scroll bar page decrease indicator (i.e., page up). |
QStyle::CE_ScrollBarSlider | 35 | Scroll bar slider. |
QStyle::CE_ScrollBarFirst | 36 | Scroll bar first line indicator (i.e., home). |
QStyle::CE_ScrollBarLast | 37 | Scroll bar last line indicator (i.e., end). |
QStyle::CE_RubberBand | 29 | Rubber band used in for example an icon view. |
QStyle::CE_FocusFrame | 38 | Focus frame that is style controlled. |
QStyle::CE_ItemViewItem | 45 | An item inside an item view. |
QStyle::CE_CustomBase | 0xf0000000 | Base value for custom control elements; custom values must be greater than this value. |
QStyle::CE_ComboBoxLabel | 39 | The label of a non-editable QComboBox. |
QStyle::CE_ToolBar | 40 | A toolbar like QToolBar. |
QStyle::CE_ToolBoxTabShape | 41 | The toolbox’s tab shape. |
QStyle::CE_ToolBoxTabLabel | 42 | The toolbox’s tab label. |
QStyle::CE_HeaderEmptyArea | 43 | The area of a header view where there are no header sections. |
QStyle::CE_ShapedFrame | 46 | The frame with the shape specified in the QStyleOptionFrame; see QFrame. |
可以看看drawControl()
4. enum QStyle::PixelMetric
enum QStyle::PixelMetric
这个枚举描述了各种可用的像素度量。像素度量是一种与样式相关的尺寸,由单个像素值表示。
Constant | Value | Description |
---|---|---|
QStyle::PM_ButtonMargin | 0 | Amount of whitespace between push button labels and the frame. |
QStyle::PM_DockWidgetTitleBarButtonMargin | 76 | Amount of whitespace between dock widget’s title bar button labels and the frame. |
QStyle::PM_ButtonDefaultIndicator | 1 | Width of the default-button indicator frame. |
QStyle::PM_MenuButtonIndicator | 2 | Width of the menu button indicator proportional to the widget height. |
QStyle::PM_ButtonShiftHorizontal | 3 | Horizontal contents shift of a button when the button is down. |
QStyle::PM_ButtonShiftVertical | 4 | Vertical contents shift of a button when the button is down. |
QStyle::PM_DefaultFrameWidth | 5 | Default frame width (usually 2). |
QStyle::PM_SpinBoxFrameWidth | 6 | Frame width of a spin box, defaults to PM_DefaultFrameWidth. |
QStyle::PM_ComboBoxFrameWidth | 7 | Frame width of a combo box, defaults to PM_DefaultFrameWidth. |
QStyle::PM_MDIFrameWidth | PM_MdiSubWindowFrameWidth | Obsolete. Use PM_MdiSubWindowFrameWidth instead. |
QStyle::PM_MdiSubWindowFrameWidth | 44 | Frame width of an MDI window. |
QStyle::PM_MDIMinimizedWidth | PM_MdiSubWindowMinimizedWidth | Obsolete. Use PM_MdiSubWindowMinimizedWidth instead. |
QStyle::PM_MdiSubWindowMinimizedWidth | 45 | Width of a minimized MDI window. |
QStyle::PM_LayoutLeftMargin | 78 | Default left margin for a QLayout. |
QStyle::PM_LayoutTopMargin | 79 | Default top margin for a QLayout. |
QStyle::PM_LayoutRightMargin | 80 | Default right margin for a QLayout. |
QStyle::PM_LayoutBottomMargin | 81 | Default bottom margin for a QLayout. |
QStyle::PM_LayoutHorizontalSpacing | 82 | Default horizontal spacing for a QLayout. |
QStyle::PM_LayoutVerticalSpacing | 83 | Default vertical spacing for a QLayout. |
QStyle::PM_MaximumDragDistance | 8 | The 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_ScrollBarExtent | 9 | Width of a vertical scroll bar and the height of a horizontal scroll bar. |
QStyle::PM_ScrollBarSliderMin | 10 | The minimum height of a vertical scroll bar’s slider and the minimum width of a horizontal scroll bar’s slider. |
QStyle::PM_SliderThickness | 11 | Total slider thickness. |
QStyle::PM_SliderControlThickness | 12 | Thickness of the slider handle. |
QStyle::PM_SliderLength | 13 | Length of the slider. |
QStyle::PM_SliderTickmarkOffset | 14 | The offset between the tickmarks and the slider. |
QStyle::PM_SliderSpaceAvailable | 15 | The available space for the slider to move. |
QStyle::PM_DockWidgetSeparatorExtent | 16 | Width of a separator in a horizontal dock window and the height of a separator in a vertical dock window. |
QStyle::PM_DockWidgetHandleExtent | 17 | Width of the handle in a horizontal dock window and the height of the handle in a vertical dock window. |
QStyle::PM_DockWidgetFrameWidth | 18 | Frame width of a dock window. |
QStyle::PM_DockWidgetTitleMargin | 73 | Margin of the dock window title. |
QStyle::PM_MenuBarPanelWidth | 33 | Frame width of a menu bar, defaults to PM_DefaultFrameWidth. |
QStyle::PM_MenuBarItemSpacing | 34 | Spacing between menu bar items. |
QStyle::PM_MenuBarHMargin | 36 | Spacing between menu bar items and left/right of bar. |
QStyle::PM_MenuBarVMargin | 35 | Spacing between menu bar items and top/bottom of bar. |
QStyle::PM_ToolBarFrameWidth | 52 | Width of the frame around toolbars. |
QStyle::PM_ToolBarHandleExtent | 53 | Width of a toolbar handle in a horizontal toolbar and the height of the handle in a vertical toolbar. |
QStyle::PM_ToolBarItemMargin | 55 | Spacing between the toolbar frame and the items. |
QStyle::PM_ToolBarItemSpacing | 54 | Spacing between toolbar items. |
QStyle::PM_ToolBarSeparatorExtent | 56 | Width of a toolbar separator in a horizontal toolbar and the height of a separator in a vertical toolbar. |
QStyle::PM_ToolBarExtensionExtent | 57 | Width of a toolbar extension button in a horizontal toolbar and the height of the button in a vertical toolbar. |
QStyle::PM_TabBarTabOverlap | 19 | Number of pixels the tabs should overlap. (Currently only used in styles, not inside of QTabBar) |
QStyle::PM_TabBarTabHSpace | 20 | Extra space added to the tab width. |
QStyle::PM_TabBarTabVSpace | 21 | Extra space added to the tab height. |
QStyle::PM_TabBarBaseHeight | 22 | Height of the area between the tab bar and the tab pages. |
QStyle::PM_TabBarBaseOverlap | 23 | Number of pixels the tab bar overlaps the tab bar base. |
QStyle::PM_TabBarScrollButtonWidth | 51 | |
QStyle::PM_TabBarTabShiftHorizontal | 49 | Horizontal pixel shift when a tab is selected. |
QStyle::PM_TabBarTabShiftVertical | 50 | Vertical pixel shift when a tab is selected. |
QStyle::PM_ProgressBarChunkWidth | 24 | Width of a chunk in a progress bar indicator. |
QStyle::PM_SplitterWidth | 25 | Width of a splitter. |
QStyle::PM_TitleBarHeight | 26 | Height of the title bar. |
QStyle::PM_IndicatorWidth | 37 | Width of a check box indicator. |
QStyle::PM_IndicatorHeight | 38 | Height of a checkbox indicator. |
QStyle::PM_ExclusiveIndicatorWidth | 39 | Width of a radio button indicator. |
QStyle::PM_ExclusiveIndicatorHeight | 40 | Height of a radio button indicator. |
QStyle::PM_MenuPanelWidth | 30 | Border width (applied on all sides) for a QMenu. |
QStyle::PM_MenuHMargin | 28 | Additional border (used on left and right) for a QMenu. |
QStyle::PM_MenuVMargin | 29 | Additional border (used for bottom and top) for a QMenu. |
QStyle::PM_MenuScrollerHeight | 27 | Height of the scroller area in a QMenu. |
QStyle::PM_MenuTearoffHeight | 31 | Height of a tear off area in a QMenu. |
QStyle::PM_MenuDesktopFrameWidth | 32 | The frame width for the menu on the desktop. |
QStyle::PM_HeaderMarkSize | 47 | The size of the sort indicator in a header. |
QStyle::PM_HeaderGripMargin | 48 | The size of the resize grip in a header. |
QStyle::PM_HeaderMargin | 46 | The size of the margin between the sort indicator and the text. |
QStyle::PM_SpinBoxSliderHeight | 58 | The height of the optional spin box slider. |
QStyle::PM_ToolBarIconSize | PM_SpinBoxSliderHeight + 4 | Default tool bar icon size |
QStyle::PM_SmallIconSize | 65 | Default small icon size |
QStyle::PM_LargeIconSize | 66 | Default large icon size |
QStyle::PM_FocusFrameHMargin | 68 | Horizontal margin that the focus frame will outset the widget by. |
QStyle::PM_FocusFrameVMargin | 67 | Vertical margin that the focus frame will outset the widget by. |
QStyle::PM_IconViewIconSize | 64 | The default size for icons in an icon view. |
QStyle::PM_ListViewIconSize | 63 | The default size for icons in a list view. |
QStyle::PM_ToolTipLabelFrameWidth | 69 | The frame width for a tool tip label. |
QStyle::PM_CheckBoxLabelSpacing | 70 | The spacing between a check box indicator and its label. |
QStyle::PM_RadioButtonLabelSpacing | 77 | The spacing between a radio button indicator and its label. |
QStyle::PM_TabBarIconSize | 71 | The default icon size for a tab bar. |
QStyle::PM_SizeGripSize | 72 | The size of a size grip. |
QStyle::PM_MessageBoxIconSize | 74 | The size of the standard icons in a message box |
QStyle::PM_ButtonIconSize | 75 | The default size of button icons |
QStyle::PM_TextCursorWidth | 85 | The width of the cursor in a line edit or text edit |
QStyle::PM_TabBar_ScrollButtonOverlap | 84 | The distance between the left and right buttons in a tab bar. |
QStyle::PM_TabCloseIndicatorWidth | 86 | The default width of a close button on a tab in a tab bar. |
QStyle::PM_TabCloseIndicatorHeight | 87 | The default height of a close button on a tab in a tab bar. |
QStyle::PM_ScrollView_ScrollBarSpacing | 88 | Distance between frame and scrollbar with SH_ScrollView_FrameOnlyAroundContents set. |
QStyle::PM_ScrollView_ScrollBarOverlap | 89 | Overlap between scroll bars and scroll content |
QStyle::PM_SubMenuOverlap | 90 | The horizontal overlap between a submenu and its parent. |
QStyle::PM_TreeViewIndentation | 91 | The indentation of items in a tree view. This enum value has been introduced in Qt 5.4. |
QStyle::PM_HeaderDefaultSectionSizeHorizontal | 92 | The default size of sections in a horizontal header. This enum value has been introduced in Qt 5.5. |
QStyle::PM_HeaderDefaultSectionSizeVertical | 93 | The default size of sections in a vertical header. This enum value has been introduced in Qt 5.5. |
QStyle::PM_TitleBarButtonIconSize | 94 | The size of button icons on a title bar. This enum value has been introduced in Qt 5.8. |
QStyle::PM_TitleBarButtonSize | 95 | The size of buttons on a title bar. This enum value has been introduced in Qt 5.8. |
QStyle::PM_CustomBase | 0xf0000000 | Base value for custom pixel metrics. Custom values must be greater than this value. |
5. enum QStyle::PrimitiveElement
enum QStyle::PrimitiveElement
这个枚举描述了各种原始元素。原始元素是常见的图形用户界面元素,例如复选框指示器或按钮斜角。
Constant | Value | Description |
---|---|---|
QStyle::PE_FrameStatusBar | PE_FrameStatusBarItem | Obsolete. Use PE_FrameStatusBarItem instead. |
QStyle::PE_PanelButtonCommand | 13 | Button used to initiate an action, for example, a QPushButton. |
QStyle::PE_FrameDefaultButton | 1 | This frame around a default button, e.g. in a dialog. |
QStyle::PE_PanelButtonBevel | 14 | Generic panel with a button bevel. |
QStyle::PE_PanelButtonTool | 15 | Panel for a Tool button, used with QToolButton. |
QStyle::PE_PanelLineEdit | 18 | Panel for a QLineEdit. |
QStyle::PE_IndicatorButtonDropDown | 24 | Indicator for a drop down button, for example, a tool button that displays a menu. |
QStyle::PE_FrameFocusRect | 3 | Generic focus indicator. |
QStyle::PE_IndicatorArrowUp | 22 | Generic Up arrow. |
QStyle::PE_IndicatorArrowDown | 19 | Generic Down arrow. |
QStyle::PE_IndicatorArrowRight | 21 | Generic Right arrow. |
QStyle::PE_IndicatorArrowLeft | 20 | Generic Left arrow. |
QStyle::PE_IndicatorSpinUp | 35 | Up symbol for a spin widget, for example a QSpinBox. |
QStyle::PE_IndicatorSpinDown | 32 | Down symbol for a spin widget. |
QStyle::PE_IndicatorSpinPlus | 34 | Increase symbol for a spin widget. |
QStyle::PE_IndicatorSpinMinus | 33 | Decrease symbol for a spin widget. |
QStyle::PE_IndicatorItemViewItemCheck | 25 | On/off indicator for a view item. |
QStyle::PE_IndicatorCheckBox | 26 | On/off indicator, for example, a QCheckBox. |
QStyle::PE_IndicatorRadioButton | 31 | Exclusive on/off indicator, for example, a QRadioButton. |
QStyle::PE_IndicatorDockWidgetResizeHandle | 27 | Resize handle for dock windows. |
QStyle::PE_Frame | 0 | Generic frame |
QStyle::PE_FrameMenu | 6 | Frame for popup windows/menus; see also QMenu. |
QStyle::PE_PanelMenuBar | 16 | Panel for menu bars. |
QStyle::PE_PanelScrollAreaCorner | 40 | Panel at the bottom-right (or bottom-left) corner of a scroll area. |
QStyle::PE_FrameDockWidget | 2 | Panel frame for dock windows and toolbars. |
QStyle::PE_FrameTabWidget | 8 | Frame for tab widgets. |
QStyle::PE_FrameLineEdit | 5 | Panel frame for line edits. |
QStyle::PE_FrameGroupBox | 4 | Panel frame around group boxes. |
QStyle::PE_FrameButtonBevel | 10 | Panel frame for a button bevel. |
QStyle::PE_FrameButtonTool | 11 | Panel frame for a tool button. |
QStyle::PE_IndicatorHeaderArrow | 28 | Arrow used to indicate sorting on a list or table header. |
QStyle::PE_FrameStatusBarItem | 7 | Frame for an item of a status bar; see also QStatusBar. |
QStyle::PE_FrameWindow | 9 | Frame around a MDI window or a docking window. |
QStyle::PE_IndicatorMenuCheckMark | 29 | Check mark used in a menu. |
QStyle::PE_IndicatorProgressChunk | 30 | Section of a progress bar indicator; see also QProgressBar. |
QStyle::PE_IndicatorBranch | 23 | Lines used to represent the branch of a tree in a tree view. |
QStyle::PE_IndicatorToolBarHandle | 36 | The handle of a toolbar. |
QStyle::PE_IndicatorToolBarSeparator | 37 | The separator in a toolbar. |
QStyle::PE_PanelToolBar | 17 | The panel for a toolbar. |
QStyle::PE_PanelTipLabel | 38 | The panel for a tip label. |
QStyle::PE_FrameTabBarBase | 12 | The frame that is drawn for a tab bar, ususally drawn for a tab bar that isn’t part of a tab widget. |
QStyle::PE_IndicatorTabTear | 39 | Deprecated. Use PE_IndicatorTabTearLeft instead. |
QStyle::PE_IndicatorTabTearLeft | PE_IndicatorTabTear | An indicator that a tab is partially scrolled out on the left side of the visible tab bar when there are many tabs. |
QStyle::PE_IndicatorTabTearRight | 49 | An indicator that a tab is partially scrolled out on the right side of the visible tab bar when there are many tabs. |
QStyle::PE_IndicatorColumnViewArrow | 42 | An arrow in a QColumnView. |
QStyle::PE_Widget | 41 | A plain QWidget. |
QStyle::PE_CustomBase | 0xf000000 | Base value for custom primitive elements. All values above this are reserved for custom use. Custom values must be greater than this value. |
QStyle::PE_IndicatorItemViewItemDrop | 43 | An 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_PanelItemViewItem | 44 | The background for an item in an item view. |
QStyle::PE_PanelItemViewRow | 45 | The background of a row in an item view. |
QStyle::PE_PanelStatusBar | 46 | The panel for a status bar. |
QStyle::PE_IndicatorTabClose | 47 | The close button on a tab bar. |
QStyle::PE_PanelMenu | 48 | The panel for a menu. |
可以看看drawPrimitive();
6. enum QStyle::RequestSoftwareInputPanel
enum QStyle::RequestSoftwareInputPanel
这个枚举描述了在什么情况下具有输入功能的小部件会请求软件输入面板。
Constant | Value | Description |
---|---|---|
QStyle::RSIP_OnMouseClickAndAlreadyFocused | 0 | Requests an input panel if the user clicks on the widget, but only if it is already focused. |
QStyle::RSIP_OnMouseClick | 1 | Requests an input panel if the user clicks on the widget. |
7. enum QStyleStandardPixmap
enum QStyle::StandardPixmap
这个枚举描述了可用的标准像素图。标准像素图是可以遵循某些现有GUI样式或指南的像素图。
Constant | Value | Description |
---|---|---|
QStyle::SP_TitleBarMinButton | 1 | Minimize button on title bars (e.g., in QMdiSubWindow). |
QStyle::SP_TitleBarMenuButton | 0 | Menu button on a title bar. |
QStyle::SP_TitleBarMaxButton | 2 | Maximize button on title bars. |
QStyle::SP_TitleBarCloseButton | 3 | Close button on title bars. |
QStyle::SP_TitleBarNormalButton | 4 | Normal (restore) button on title bars. |
QStyle::SP_TitleBarShadeButton | 5 | Shade button on title bars. |
QStyle::SP_TitleBarUnshadeButton | 6 | Unshade button on title bars. |
QStyle::SP_TitleBarContextHelpButton | 7 | The Context help button on title bars. |
QStyle::SP_MessageBoxInformation | 9 | The “information” icon. |
QStyle::SP_MessageBoxWarning | 10 | The “warning” icon. |
QStyle::SP_MessageBoxCritical | 11 | The “critical” icon. |
QStyle::SP_MessageBoxQuestion | 12 | The “question” icon. |
QStyle::SP_DesktopIcon | 13 | The “desktop” icon. |
QStyle::SP_TrashIcon | 14 | The “trash” icon. |
QStyle::SP_ComputerIcon | 15 | The “My computer” icon. |
QStyle::SP_DriveFDIcon | 16 | The floppy icon. |
QStyle::SP_DriveHDIcon | 17 | The harddrive icon. |
QStyle::SP_DriveCDIcon | 18 | The CD icon. |
QStyle::SP_DriveDVDIcon | 19 | The DVD icon. |
QStyle::SP_DriveNetIcon | 20 | The network icon. |
QStyle::SP_DirHomeIcon | 56 | The home directory icon. |
QStyle::SP_DirOpenIcon | 21 | The open directory icon. |
QStyle::SP_DirClosedIcon | 22 | The closed directory icon. |
QStyle::SP_DirIcon | 38 | The directory icon. |
QStyle::SP_DirLinkIcon | 23 | The link to directory icon. |
QStyle::SP_DirLinkOpenIcon | 24 | The link to open directory icon. |
QStyle::SP_FileIcon | 25 | The file icon. |
QStyle::SP_FileLinkIcon | 26 | The link to file icon. |
QStyle::SP_FileDialogStart | 29 | The “start” icon in a file dialog. |
QStyle::SP_FileDialogEnd | 30 | The “end” icon in a file dialog. |
QStyle::SP_FileDialogToParent | 31 | The “parent directory” icon in a file dialog. |
QStyle::SP_FileDialogNewFolder | 32 | The “create new folder” icon in a file dialog. |
QStyle::SP_FileDialogDetailedView | 33 | The detailed view icon in a file dialog. |
QStyle::SP_FileDialogInfoView | 34 | The file info icon in a file dialog. |
QStyle::SP_FileDialogContentsView | 35 | The contents view icon in a file dialog. |
QStyle::SP_FileDialogListView | 36 | The list view icon in a file dialog. |
QStyle::SP_FileDialogBack | 37 | The back arrow in a file dialog. |
QStyle::SP_DockWidgetCloseButton | 8 | Close button on dock windows (see also QDockWidget). |
QStyle::SP_ToolBarHorizontalExtensionButton | 27 | Extension button for horizontal toolbars. |
QStyle::SP_ToolBarVerticalExtensionButton | 28 | Extension button for vertical toolbars. |
QStyle::SP_DialogOkButton | 39 | Icon for a standard OK button in a QDialogButtonBox. |
QStyle::SP_DialogCancelButton | 40 | Icon for a standard Cancel button in a QDialogButtonBox. |
QStyle::SP_DialogHelpButton | 41 | Icon for a standard Help button in a QDialogButtonBox. |
QStyle::SP_DialogOpenButton | 42 | Icon for a standard Open button in a QDialogButtonBox. |
QStyle::SP_DialogSaveButton | 43 | Icon for a standard Save button in a QDialogButtonBox. |
QStyle::SP_DialogCloseButton | 44 | Icon for a standard Close button in a QDialogButtonBox. |
QStyle::SP_DialogApplyButton | 45 | Icon for a standard Apply button in a QDialogButtonBox. |
QStyle::SP_DialogResetButton | 46 | Icon for a standard Reset button in a QDialogButtonBox. |
QStyle::SP_DialogDiscardButton | 47 | Icon for a standard Discard button in a QDialogButtonBox. |
QStyle::SP_DialogYesButton | 48 | Icon for a standard Yes button in a QDialogButtonBox. |
QStyle::SP_DialogNoButton | 49 | Icon for a standard No button in a QDialogButtonBox. |
QStyle::SP_ArrowUp | 50 | Icon arrow pointing up. |
QStyle::SP_ArrowDown | 51 | Icon arrow pointing down. |
QStyle::SP_ArrowLeft | 52 | Icon arrow pointing left. |
QStyle::SP_ArrowRight | 53 | Icon arrow pointing right. |
QStyle::SP_ArrowBack | 54 | Equivalent to SP_ArrowLeft when the current layout direction is Qt::LeftToRight, otherwise SP_ArrowRight. |
QStyle::SP_ArrowForward | 55 | Equivalent to SP_ArrowRight when the current layout direction is Qt::LeftToRight, otherwise SP_ArrowLeft. |
QStyle::SP_CommandLink | 57 | Icon used to indicate a Vista style command link glyph. |
QStyle::SP_VistaShield | 58 | Icon used to indicate UAC prompts on Windows Vista. This will return a null pixmap or icon on all other platforms. |
QStyle::SP_BrowserReload | 59 | Icon indicating that the current page should be reloaded. |
QStyle::SP_BrowserStop | 60 | Icon indicating that the page loading should stop. |
QStyle::SP_MediaPlay | 61 | Icon indicating that media should begin playback. |
QStyle::SP_MediaStop | 62 | Icon indicating that media should stop playback. |
QStyle::SP_MediaPause | 63 | Icon indicating that media should pause playback. |
QStyle::SP_MediaSkipForward | 64 | Icon indicating that media should skip forward. |
QStyle::SP_MediaSkipBackward | 65 | Icon indicating that media should skip backward. |
QStyle::SP_MediaSeekForward | 66 | Icon indicating that media should seek forward. |
QStyle::SP_MediaSeekBackward | 67 | Icon indicating that media should seek backward. |
QStyle::SP_MediaVolume | 68 | Icon indicating a volume control. |
QStyle::SP_MediaVolumeMuted | 69 | Icon indicating a muted volume control. |
QStyle::SP_LineEditClearButton | 70 | Icon for a standard clear button in a QLineEdit. This enum value was added in Qt 5.2. |
QStyle::SP_DialogYesToAllButton | 71 | Icon for a standard YesToAll button in a QDialogButtonBox. This enum value was added in Qt 5.14. |
QStyle::SP_DialogNoToAllButton | 72 | Icon for a standard NoToAll button in a QDialogButtonBox. This enum value was added in Qt 5.14. |
QStyle::SP_DialogSaveAllButton | 73 | Icon for a standard SaveAll button in a QDialogButtonBox. This enum value was added in Qt 5.14. |
QStyle::SP_DialogAbortButton | 74 | Icon for a standard Abort button in a QDialogButtonBox. This enum value was added in Qt 5.14. |
QStyle::SP_DialogRetryButton | 75 | Icon for a standard Retry button in a QDialogButtonBox. This enum value was added in Qt 5.14. |
QStyle::SP_DialogIgnoreButton | 76 | Icon for a standard Ignore button in a QDialogButtonBox. This enum value was added in Qt 5.14. |
QStyle::SP_RestoreDefaultsButton | 77 | Icon for a standard RestoreDefaults button in a QDialogButtonBox. This enum value was added in Qt 5.14. |
QStyle::SP_CustomBase | 0xf0000000 | Base 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。
请注意,并不是所有原始元素都会使用所有这些标志,并且这些标志对不同的项目可能有不同的含义。
Constant | Value | Description |
---|---|---|
QStyle::State_None | 0x00000000 | Indicates that the widget does not have a state. |
QStyle::State_Active | 0x00010000 | Indicates that the widget is active. |
QStyle::State_AutoRaise | 0x00001000 | Used to indicate if auto-raise appearance should be used on a tool button. |
QStyle::State_Children | 0x00080000 | Used to indicate if an item view branch has children. |
QStyle::State_DownArrow | 0x00000040 | Used to indicate if a down arrow should be visible on the widget. |
QStyle::State_Editing | 0x00400000 | Used to indicate if an editor is opened on the widget. |
QStyle::State_Enabled | 0x00000001 | Used to indicate if the widget is enabled. |
QStyle::State_HasEditFocus | 0x01000000 | Used to indicate if the widget currently has edit focus. |
QStyle::State_HasFocus | 0x00000100 | Used to indicate if the widget has focus. |
QStyle::State_Horizontal | 0x00000080 | Used to indicate if the widget is laid out horizontally, for example. a tool bar. |
QStyle::State_KeyboardFocusChange | 0x00800000 | Used to indicate if the focus was changed with the keyboard, e.g., tab, backtab or shortcut. |
QStyle::State_MouseOver | 0x00002000 | Used to indicate if the widget is under the mouse. |
QStyle::State_NoChange | 0x00000010 | Used to indicate a tri-state checkbox. |
QStyle::State_Off | 0x00000008 | Used to indicate if the widget is not checked. |
QStyle::State_On | 0x00000020 | Used to indicate if the widget is checked. |
QStyle::State_Raised | 0x00000002 | Used to indicate if a button is raised. |
QStyle::State_ReadOnly | 0x02000000 | Used to indicate if a widget is read-only. |
QStyle::State_Selected | 0x00008000 | Used to indicate if a widget is selected. |
QStyle::State_Item | 0x00100000 | Used by item views to indicate if a horizontal branch should be drawn. |
QStyle::State_Open | 0x00040000 | Used by item views to indicate if the tree branch is open. |
QStyle::State_Sibling | 0x00200000 | Used by item views to indicate if a vertical line needs to be drawn (for siblings). |
QStyle::State_Sunken | 0x00000004 | Used to indicate if the widget is sunken or pressed. |
QStyle::State_UpArrow | 0x00004000 | Used to indicate if an up arrow should be visible on the widget. |
QStyle::State_Mini | 0x08000000 | Used to indicate a mini style Mac widget or button. |
QStyle::State_Small | 0x04000000 | Used 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的提示。
Constant | Value | Description |
---|---|---|
QStyle::SH_EtchDisabledText | 0 | Disabled text is “etched” as it is on Windows. |
QStyle::SH_DitherDisabledText | 1 | Disabled text is dithered as it is on Motif. |
QStyle::SH_ScrollBar_ContextMenu | 62 | Whether or not a scroll bar has a context menu. |
QStyle::SH_ScrollBar_MiddleClickAbsolutePosition | 2 | A 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_LeftClickAbsolutePosition | 39 | A 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_ScrollWhenPointerLeavesControl | 3 | A 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_RollBetweenButtons | 63 | A 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_Alignment | 5 | The alignment for tabs in a QTabWidget. Possible values are Qt::AlignLeft, Qt::AlignCenter and Qt::AlignRight. |
QStyle::SH_Header_ArrowAlignment | 6 | The 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_SnapToValue | 7 | Sliders snap to values while moving, as they do on Windows. |
QStyle::SH_Slider_SloppyKeyEvents | 8 | Key presses handled in a sloppy manner, i.e., left on a vertical slider subtracts a line. |
QStyle::SH_ProgressDialog_CenterCancelButton | 9 | Center button on progress dialogs, otherwise right aligned. |
QStyle::SH_ProgressDialog_TextLabelAlignment | 10 | The alignment for text labels in progress dialogs; Qt::AlignCenter on Windows, Qt::AlignVCenter otherwise. |
QStyle::SH_PrintDialog_RightAlignButtons | 11 | Right align buttons in the print dialog, as done on Windows. |
QStyle::SH_MainWindow_SpaceBelowMenuBar | 12 | One or two pixel space between the menu bar and the dockarea, as done on Windows. |
QStyle::SH_FontDialog_SelectAssociatedText | 13 | Select 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_KeyboardSearch | 66 | Typing causes a menu to be search for relevant items, otherwise only mnemnonic is considered. |
QStyle::SH_Menu_AllowActiveAndDisabled | 14 | Allows disabled menu items to be active. |
QStyle::SH_Menu_SpaceActivatesItem | 15 | Pressing the space bar activates the item, as done on Motif. |
QStyle::SH_Menu_SubMenuPopupDelay | 16 | The number of milliseconds to wait before opening a submenu (256 on Windows, 96 on Motif). |
QStyle::SH_Menu_Scrollable | 30 | Whether popup menus must support scrolling. |
QStyle::SH_Menu_SloppySubMenus | 33 | Whether 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_SubMenuUniDirection | 106 | Since 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_SubMenuUniDirectionFailCount | 107 | Since 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_SubMenuSloppySelectOtherActions | 108 | Since Qt 5.5. Should other action items be selected when the mouse moves towards a sloppy submenu. |
QStyle::SH_Menu_SubMenuSloppyCloseTimeout | 109 | Since Qt 5.5. The timeout used to close sloppy submenus. |
QStyle::SH_Menu_SubMenuResetWhenReenteringParent | 110 | Since 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_SubMenuDontStartSloppyOnLeave | 111 | Since Qt 5.5. Do not start sloppy timers when the mouse leaves a sub-menu. |
QStyle::SH_ScrollView_FrameOnlyAroundContents | 17 | Whether scrollviews draw their frame only around contents (like Motif), or around contents, scroll bars and corner widgets (like Windows). |
QStyle::SH_MenuBar_AltKeyNavigation | 18 | Menu bars items are navigable by pressing Alt, followed by using the arrow keys to select the desired item. |
QStyle::SH_ComboBox_ListMouseTracking | 19 | Mouse tracking in combobox drop-down lists. |
QStyle::SH_Menu_MouseTracking | 20 | Mouse tracking in popup menus. |
QStyle::SH_MenuBar_MouseTracking | 21 | Mouse tracking in menu bars. |
QStyle::SH_Menu_FillScreenWithScroll | 45 | Whether scrolling popups should fill the screen as they are scrolled. |
QStyle::SH_Menu_SelectionWrap | 74 | Whether popups should allow the selections to wrap, that is when selection should the next item be the first item. |
QStyle::SH_ItemView_ChangeHighlightOnFocus | 22 | Gray out selected items when losing focus. |
QStyle::SH_Widget_ShareActivation | 23 | Turn on sharing activation with floating modeless dialogs. |
QStyle::SH_TabBar_SelectMouseType | 4 | Which type of mouse event should cause a tab to be selected. |
QStyle::SH_ListViewExpand_SelectMouseType | 40 | Which type of mouse event should cause a list view expansion to be selected. |
QStyle::SH_TabBar_PreferNoArrows | 38 | Whether a tab bar should suggest a size to prevent scoll arrows. |
QStyle::SH_ComboBox_Popup | 25 | Allows popups as a combobox drop-down menu. |
QStyle::SH_Workspace_FillSpaceOnMaximize | 24 | The workspace should maximize the client area. |
QStyle::SH_TitleBar_NoBorder | 26 | The title bar has no border. |
QStyle::SH_ScrollBar_StopMouseOverSlider | SH_Slider_StopMouseOverSlider | Obsolete. Use SH_Slider_StopMouseOverSlider instead. |
QStyle::SH_Slider_StopMouseOverSlider | 27 | Stops auto-repeat when the slider reaches the mouse position. |
QStyle::SH_BlinkCursorWhenTextSelected | 28 | Whether cursor should blink when text is selected. |
QStyle::SH_RichText_FullWidthSelection | 29 | Whether richtext selections should extend to the full width of the document. |
QStyle::SH_GroupBox_TextLabelVerticalAlignment | 31 | How to vertically align a group box’s text label. |
QStyle::SH_GroupBox_TextLabelColor | 32 | How to paint a group box’s text label. |
QStyle::SH_DialogButtons_DefaultButton | 36 | Which button gets the default status in a dialog’s button widget. |
QStyle::SH_ToolBox_SelectedPageTitleBold | 37 | Boldness of the selected page title in a QToolBox. |
QStyle::SH_LineEdit_PasswordCharacter | 35 | The Unicode character to be used for passwords. |
QStyle::SH_LineEdit_PasswordMaskDelay | 104 | Determines the delay before visible character is masked with password character, in milliseconds. This enum value was added in Qt 5.4. |
QStyle::SH_Table_GridLineColor | 34 | The RGBA value of the grid for a table. |
QStyle::SH_UnderlineShortcut | 41 | Whether shortcuts are underlined. |
QStyle::SH_SpellCheckUnderlineStyle | 72 | Obsolete. Use SpellCheckUnderlineStyle hint in QPlatformTheme instead. |
QStyle::SH_SpinBox_AnimateButton | 42 | Animate a click when up or down is pressed in a spin box. |
QStyle::SH_SpinBox_KeyPressAutoRepeatRate | 43 | Auto-repeat interval for spinbox key presses. |
QStyle::SH_SpinBox_ClickAutoRepeatRate | 44 | Auto-repeat interval for spinbox mouse clicks. |
QStyle::SH_SpinBox_ClickAutoRepeatThreshold | 84 | Auto-repeat threshold for spinbox mouse clicks. |
QStyle::SH_ToolTipLabel_Opacity | 46 | An integer indicating the opacity for the tip label, 0 is completely transparent, 255 is completely opaque. |
QStyle::SH_DrawMenuBarSeparator | 47 | Indicates whether or not the menu bar draws separators. |
QStyle::SH_TitleBar_ModifyNotification | 48 | Indicates if the title bar should show a ‘*’ for windows that are modified. |
QStyle::SH_Button_FocusPolicy | 49 | The default focus policy for buttons. |
QStyle::SH_CustomBase | 0xf0000000 | Base value for custom style hints. Custom values must be greater than this value. |
QStyle::SH_MessageBox_UseBorderForButtonSpacing | 50 | A 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_CenterButtons | 73 | A boolean indicating whether the buttons in the message box should be centered or not (see QDialogButtonBox::setCentered()). |
QStyle::SH_MessageBox_TextInteractionFlags | 70 | A boolean indicating if the text in a message box should allow user interfactions (e.g. selection) or not. |
QStyle::SH_TitleBar_AutoRaise | 51 | A boolean indicating whether controls on a title bar ought to update when the mouse is over them. |
QStyle::SH_ToolButton_PopupDelay | 52 | An int indicating the popup delay in milliseconds for menus attached to tool buttons. |
QStyle::SH_FocusFrame_Mask | 53 | The mask of the focus frame. |
QStyle::SH_RubberBand_Mask | 54 | The mask of the rubber band. |
QStyle::SH_WindowFrame_Mask | 55 | The mask of the window frame. |
QStyle::SH_SpinControls_DisableOnBounds | 56 | Determines if the spin controls will shown as disabled when reaching the spin range boundary. |
QStyle::SH_Dial_BackgroundRole | 57 | Defines the style’s preferred background role (as QPalette::ColorRole) for a dial widget. |
QStyle::SH_ComboBox_LayoutDirection | 58 | The layout direction for the combo box. By default it should be the same as indicated by the QStyleOption::direction variable. |
QStyle::SH_ItemView_EllipsisLocation | 59 | The location where ellipses should be added for item text that is too long to fit in an view item. |
QStyle::SH_ItemView_ShowDecorationSelected | 60 | When an item in an item view is selected, also highlight the branch or other decoration. |
QStyle::SH_ItemView_ActivateItemOnSingleClick | 61 | Emit 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_AbsoluteSetButtons | 64 | Which mouse buttons cause a slider to set the value to the position clicked on. |
QStyle::SH_Slider_PageSetButtons | 65 | Which mouse buttons cause a slider to page step the value. |
QStyle::SH_TabBar_ElideMode | 67 | The default eliding style for a tab bar. |
QStyle::SH_DialogButtonLayout | 68 | Controls how buttons are laid out in a QDialogButtonBox, returns a QDialogButtonBox::ButtonLayout enum. |
QStyle::SH_WizardStyle | 79 | Controls the look and feel of a QWizard. Returns a QWizard::WizardStyle enum. |
QStyle::SH_FormLayoutWrapPolicy | 86 | Provides a default for how rows are wrapped in a QFormLayout. Returns a QFormLayout::RowWrapPolicy enum. |
QStyle::SH_FormLayoutFieldGrowthPolicy | 89 | Provides a default for how fields can grow in a QFormLayout. Returns a QFormLayout::FieldGrowthPolicy enum. |
QStyle::SH_FormLayoutFormAlignment | 90 | Provides a default for how a QFormLayout aligns its contents within the available space. Returns a Qt::Alignment enum. |
QStyle::SH_FormLayoutLabelAlignment | 91 | Provides a default for how a QFormLayout aligns labels within the available space. Returns a Qt::Alignment enum. |
QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren | 80 | Controls whether the tree view will select the first child when it is exapanded and the right arrow key is pressed. |
QStyle::SH_ComboBox_PopupFrameStyle | 69 | The frame style used when drawing a combobox popup menu. |
QStyle::SH_DialogButtonBox_ButtonsHaveIcons | 71 | Indicates whether or not StandardButtons in QDialogButtonBox should have icons or not. |
QStyle::SH_ItemView_MovementWithoutUpdatingSelection | 75 | The item view is able to indicate a current item without changing the selection. |
QStyle::SH_ToolTip_Mask | 76 | The mask of a tool tip. |
QStyle::SH_FocusFrame_AboveWidget | 77 | The FocusFrame is stacked above the widget that it is “focusing on”. |
QStyle::SH_TextControl_FocusIndicatorTextCharFormat | 78 | Specifies 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_FlashTriggeredItem | 82 | Flash triggered item. |
QStyle::SH_Menu_FadeOutOnHide | 83 | Fade out the menu instead of hiding it immediately. |
QStyle::SH_TabWidget_DefaultTabPosition | 87 | Default position of the tab bar in a tab widget. |
QStyle::SH_ToolBar_Movable | 88 | Determines if the tool bar is movable by default. |
QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea | 85 | Whether QTreeView paints alternating row colors for the area that does not have any items. |
QStyle::SH_Menu_Mask | 81 | The mask for a popup menu. |
QStyle::SH_ItemView_DrawDelegateFrame | 92 | Determines if there should be a frame for a delegate widget. |
QStyle::SH_TabBar_CloseButtonPosition | 93 | Determines the position of the close button on a tab in a tab bar. |
QStyle::SH_DockWidget_ButtonsHaveFrame | 94 | Determines if dockwidget buttons should have frames. Default is true. |
QStyle::SH_ToolButtonStyle | 95 | Determines the default system style for tool buttons that uses Qt::ToolButtonFollowStyle. |
QStyle::SH_RequestSoftwareInputPanel | 96 | Determines when a software input panel should be requested by input widgets. Returns an enum of type QStyle::RequestSoftwareInputPanel. |
QStyle::SH_ScrollBar_Transient | 97 | Determines 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_SupportsSections | 98 | Determines 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_WakeUpDelay | 99 | Determines the delay before a tooltip is shown, in milliseconds. |
QStyle::SH_ToolTip_FallAsleepDelay | 100 | Determines 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_Animate | 101 | Deprecated. Use SH_Widget_Animation_Duration instead. |
QStyle::SH_Splitter_OpaqueResize | 102 | Determines if widgets are resized dynamically (opaquely) while interactively moving the splitter. This enum value was introduced in Qt 5.2. |
QStyle::SH_TabBar_ChangeCurrentDelay | 105 | Determines 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_ScrollMode | 112 | The 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_ShowToolTipsOnButtons | 113 | Determines 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_Duration | 114 | Determines 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_AllowWheelScrolling | 115 | Determines 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_ButtonsInsideFrame | 116 | Determines if the spin box buttons are inside the line edit frame. This enum value has been introduced in Qt 5.11. |
QStyle::SH_SpinBox_StepModifier | 117 | Determines 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)中的控件元素。
Constant | Value | Description |
---|---|---|
QStyle::SC_None | 0x00000000 | Special value that matches no other sub control. |
QStyle::SC_ScrollBarAddLine | 0x00000001 | Scroll bar add line (i.e., down/right arrow); see also QScrollBar. |
QStyle::SC_ScrollBarSubLine | 0x00000002 | Scroll bar sub line (i.e., up/left arrow). |
QStyle::SC_ScrollBarAddPage | 0x00000004 | Scroll bar add page (i.e., page down). |
QStyle::SC_ScrollBarSubPage | 0x00000008 | Scroll bar sub page (i.e., page up). |
QStyle::SC_ScrollBarFirst | 0x00000010 | Scroll bar first line (i.e., home). |
QStyle::SC_ScrollBarLast | 0x00000020 | Scroll bar last line (i.e., end). |
QStyle::SC_ScrollBarSlider | 0x00000040 | Scroll bar slider handle. |
QStyle::SC_ScrollBarGroove | 0x00000080 | Special sub-control which contains the area in which the slider handle may move. |
QStyle::SC_SpinBoxUp | 0x00000001 | Spin widget up/increase; see also QSpinBox. |
QStyle::SC_SpinBoxDown | 0x00000002 | Spin widget down/decrease. |
QStyle::SC_SpinBoxFrame | 0x00000004 | Spin widget frame. |
QStyle::SC_SpinBoxEditField | 0x00000008 | Spin widget edit field. |
QStyle::SC_ComboBoxEditField | 0x00000002 | Combobox edit field; see also QComboBox. |
QStyle::SC_ComboBoxArrow | 0x00000004 | Combobox arrow button. |
QStyle::SC_ComboBoxFrame | 0x00000001 | Combobox frame. |
QStyle::SC_ComboBoxListBoxPopup | 0x00000008 | The reference rectangle for the combobox popup. Used to calculate the position of the popup. |
QStyle::SC_SliderGroove | 0x00000001 | Special sub-control which contains the area in which the slider handle may move. |
QStyle::SC_SliderHandle | 0x00000002 | Slider handle. |
QStyle::SC_SliderTickmarks | 0x00000004 | Slider tickmarks. |
QStyle::SC_ToolButton | 0x00000001 | Tool button (see also QToolButton). |
QStyle::SC_ToolButtonMenu | 0x00000002 | Sub-control for opening a popup menu in a tool button. |
QStyle::SC_TitleBarSysMenu | 0x00000001 | System menu button (i.e., restore, close, etc.). |
QStyle::SC_TitleBarMinButton | 0x00000002 | Minimize button. |
QStyle::SC_TitleBarMaxButton | 0x00000004 | Maximize button. |
QStyle::SC_TitleBarCloseButton | 0x00000008 | Close button. |
QStyle::SC_TitleBarLabel | 0x00000100 | Window title label. |
QStyle::SC_TitleBarNormalButton | 0x00000010 | Normal (restore) button. |
QStyle::SC_TitleBarShadeButton | 0x00000020 | Shade button. |
QStyle::SC_TitleBarUnshadeButton | 0x00000040 | Unshade button. |
QStyle::SC_TitleBarContextHelpButton | 0x00000080 | Context Help button. |
QStyle::SC_DialHandle | 0x00000002 | The handle of the dial (i.e. what you use to control the dial). |
QStyle::SC_DialGroove | 0x00000001 | The groove for the dial. |
QStyle::SC_DialTickmarks | 0x00000004 | The tickmarks for the dial. |
QStyle::SC_GroupBoxFrame | 0x00000008 | The frame of a group box. |
QStyle::SC_GroupBoxLabel | 0x00000002 | The title of a group box. |
QStyle::SC_GroupBoxCheckBox | 0x00000001 | The optional check box of a group box. |
QStyle::SC_GroupBoxContents | 0x00000004 | The group box contents. |
QStyle::SC_MdiNormalButton | 0x00000002 | The normal button for a MDI subwindow in the menu bar. |
QStyle::SC_MdiMinButton | 0x00000001 | The minimize button for a MDI subwindow in the menu bar. |
QStyle::SC_MdiCloseButton | 0x00000004 | The close button for a MDI subwindow in the menu bar. |
QStyle::SC_All | 0xffffffff | Special value that matches all sub-controls. |
SubControls
类型是 QFlags<SubControl>
的typedef,存储了 SubControl
值的OR运算集合。
可以看看 ComplexControl
11. enum QStyle::SubElement
这个枚举表示了一个小部件的子区域。样式实现使用这些区域来绘制小部件的不同部分。
Constant | Value | Description |
---|---|---|
QStyle::SE_PushButtonContents | 0 | Area containing the label (icon with text or pixmap). |
QStyle::SE_PushButtonFocusRect | 1 | Area for the focus rect (usually larger than the contents rect). |
QStyle::SE_PushButtonLayoutItem | 38 | Area that counts for the parent layout. |
QStyle::SE_PushButtonBevel | 57 | [since 5.15] Area used for the bevel of the button. |
QStyle::SE_CheckBoxIndicator | 2 | Area for the state indicator (e.g., check mark). |
QStyle::SE_CheckBoxContents | 3 | Area for the label (text or pixmap). |
QStyle::SE_CheckBoxFocusRect | 4 | Area for the focus indicator. |
QStyle::SE_CheckBoxClickRect | 5 | Clickable area, defaults to SE_CheckBoxFocusRect. |
QStyle::SE_CheckBoxLayoutItem | 32 | Area that counts for the parent layout. |
QStyle::SE_DateTimeEditLayoutItem | 34 | Area that counts for the parent layout. |
QStyle::SE_RadioButtonIndicator | 6 | Area for the state indicator. |
QStyle::SE_RadioButtonContents | 7 | Area for the label. |
QStyle::SE_RadioButtonFocusRect | 8 | Area for the focus indicator. |
QStyle::SE_RadioButtonClickRect | 9 | Clickable area, defaults to SE_RadioButtonFocusRect. |
QStyle::SE_RadioButtonLayoutItem | 39 | Area that counts for the parent layout. |
QStyle::SE_ComboBoxFocusRect | 10 | Area for the focus indicator. |
QStyle::SE_SliderFocusRect | 11 | Area for the focus indicator. |
QStyle::SE_SliderLayoutItem | 40 | Area that counts for the parent layout. |
QStyle::SE_SpinBoxLayoutItem | 41 | Area that counts for the parent layout. |
QStyle::SE_ProgressBarGroove | 12 | Area for the groove. |
QStyle::SE_ProgressBarContents | 13 | Area for the progress indicator. |
QStyle::SE_ProgressBarLabel | 14 | Area for the text label. |
QStyle::SE_ProgressBarLayoutItem | 37 | Area that counts for the parent layout. |
QStyle::SE_FrameContents | 27 | Area for a frame’s contents. |
QStyle::SE_ShapedFrameContents | 52 | Area for a frame’s contents using the shape in QStyleOptionFrame; see QFrame |
QStyle::SE_FrameLayoutItem | 43 | Area that counts for the parent layout. |
QStyle::SE_HeaderArrow | 17 | Area for the sort indicator for a header. |
QStyle::SE_HeaderLabel | 16 | Area for the label in a header. |
QStyle::SE_LabelLayoutItem | SE_DateTimeEditLayoutItem + 2 | Area that counts for the parent layout. |
QStyle::SE_LineEditContents | 26 | Area for a line edit’s contents. |
QStyle::SE_TabWidgetLeftCorner | 21 | Area for the left corner widget in a tab widget. |
QStyle::SE_TabWidgetRightCorner | 22 | Area for the right corner widget in a tab widget. |
QStyle::SE_TabWidgetTabBar | 18 | Area for the tab bar widget in a tab widget. |
QStyle::SE_TabWidgetTabContents | 20 | Area for the contents of the tab widget. |
QStyle::SE_TabWidgetTabPane | 19 | Area for the pane of a tab widget. |
QStyle::SE_TabWidgetLayoutItem | 45 | Area that counts for the parent layout. |
QStyle::SE_ToolBoxTabContents | 15 | Area for a toolbox tab’s icon and label. |
QStyle::SE_ToolButtonLayoutItem | 42 | Area that counts for the parent layout. |
QStyle::SE_ItemViewItemCheckIndicator | 23 | Area for a view item’s check mark. |
QStyle::SE_TabBarTearIndicator | 24 | Deprecated. Use SE_TabBarTearIndicatorLeft instead. |
QStyle::SE_TabBarTearIndicatorLeft | SE_TabBarTearIndicator | Area for the tear indicator on the left side of a tab bar with scroll arrows. |
QStyle::SE_TabBarTearIndicatorRight | 56 | Area for the tear indicator on the right side of a tab bar with scroll arrows. |
QStyle::SE_TabBarScrollLeftButton | 54 | Area for the scroll left button on a tab bar with scroll buttons. |
QStyle::SE_TabBarScrollRightButton | 55 | Area for the scroll right button on a tab bar with scroll buttons. |
QStyle::SE_TreeViewDisclosureItem | 25 | Area for the actual disclosure item in a tree branch. |
QStyle::SE_GroupBoxLayoutItem | 44 | Area that counts for the parent layout. |
QStyle::SE_CustomBase | 0xf0000000 | Base value for custom sub-elements. Custom values must be greater than this value. |
QStyle::SE_DockWidgetFloatButton | 29 | The float button of a dock widget. |
QStyle::SE_DockWidgetTitleBarText | 30 | The text bounds of the dock widgets title. |
QStyle::SE_DockWidgetCloseButton | 28 | The close button of a dock widget. |
QStyle::SE_DockWidgetIcon | 31 | The icon of a dock widget. |
QStyle::SE_ComboBoxLayoutItem | 33 | Area that counts for the parent layout. |
QStyle::SE_ItemViewItemDecoration | 46 | Area for a view item’s decoration (icon). |
QStyle::SE_ItemViewItemText | 47 | Area for a view item’s text. |
QStyle::SE_ItemViewItemFocusRect | 48 | Area for a view item’s focus rect. |
QStyle::SE_TabBarTabLeftButton | 49 | Area for a widget on the left side of a tab in a tab bar. |
QStyle::SE_TabBarTabRightButton | 50 | Area for a widget on the right side of a tab in a tab bar. |
QStyle::SE_TabBarTabText | 51 | Area for the text on a tab in a tab bar. |
QStyle::SE_ToolBarHandle | 53 | Area 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;
返回在布局中应该用于 controls1
和 controls2
之间的间距。
orientation
指定控件是并排布置还是垂直堆叠。option
参数可以用来传递有关父小部件的额外信息。widget
参数是可选的,如果 option 为 nullptr,也可以使用 widget 参数。controls1
和controls2
是一个或多个控件类型的(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 Control | QStyleOptionComplex Subclass | Style Flag | Remark |
---|---|---|---|
CC_SpinBox | QStyleOptionSpinBox | State_Enabled | Set if the spin box is enabled. |
State_HasFocus | Set if the spin box has input focus. | ||
CC_ComboBox | QStyleOptionComboBox | State_Enabled | Set if the combobox is enabled. |
State_HasFocus | Set if the combobox has input focus. | ||
CC_ScrollBar | QStyleOptionSlider | State_Enabled | Set if the scroll bar is enabled. |
State_HasFocus | Set if the scroll bar has input focus. | ||
CC_Slider | QStyleOptionSlider | State_Enabled | Set if the slider is enabled. |
State_HasFocus | Set if the slider has input focus. | ||
CC_Dial | QStyleOptionSlider | State_Enabled | Set if the dial is enabled. |
State_HasFocus | Set if the dial has input focus. | ||
CC_ToolButton | QStyleOptionToolButton | State_Enabled | Set if the tool button is enabled. |
State_HasFocus | Set if the tool button has input focus. | ||
State_DownArrow | Set if the tool button is down (i.e., a mouse button or the space bar is pressed). | ||
State_On | Set if the tool button is a toggle button and is toggled on. | ||
State_AutoRaise | Set if the tool button has auto-raise enabled. | ||
State_Raised | Set if the button is not down, not on, and doesn’t contain the mouse when auto-raise is enabled. | ||
CC_TitleBar | QStyleOptionTitleBar | State_Enabled | Set 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 Element | QStyleOption Subclass | Style Flag | Remark |
---|---|---|---|
CE_MenuItem, CE_MenuBarItem | QStyleOptionMenuItem | State_Selected | The menu item is currently selected item. |
State_Enabled | The item is enabled. | ||
State_DownArrow | Indicates that a scroll down arrow should be drawn. | ||
State_UpArrow | Indicates that a scroll up arrow should be drawn | ||
State_HasFocus | Set if the menu bar has input focus. | ||
CE_PushButton, CE_PushButtonBevel, CE_PushButtonLabel | QStyleOptionButton | State_Enabled | Set if the button is enabled. |
State_HasFocus | Set if the button has input focus. | ||
State_Raised | Set if the button is not down, not on and not flat. | ||
State_On | Set if the button is a toggle button and is toggled on. | ||
State_Sunken | Set 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_CheckBoxLabel | QStyleOptionButton | State_Enabled | Set if the button is enabled. |
State_HasFocus | Set if the button has input focus. | ||
State_On | Set if the button is checked. | ||
State_Off | Set if the button is not checked. | ||
State_NoChange | Set if the button is in the NoChange state. | ||
State_Sunken | Set if the button is down (i.e., the mouse button or the space bar is pressed on the button). | ||
CE_ProgressBarContents, CE_ProgressBarLabel, CE_ProgressBarGroove | QStyleOptionProgressBar | State_Enabled | Set if the progress bar is enabled. |
State_HasFocus | Set if the progress bar has input focus. | ||
CE_Header, CE_HeaderSection, CE_HeaderLabel | QStyleOptionHeader | ||
CE_TabBarTab, CE_TabBarTabShape, CE_TabBarTabLabel | QStyleOptionTab | State_Enabled | Set if the tab bar is enabled. |
State_Selected | The tab bar is the currently selected tab bar. | ||
State_HasFocus | Set if the tab bar tab has input focus. | ||
CE_ToolButtonLabel | QStyleOptionToolButton | State_Enabled | Set if the tool button is enabled. |
State_HasFocus | Set if the tool button has input focus. | ||
State_Sunken | Set if the tool button is down (i.e., a mouse button or the space bar is pressed). | ||
State_On | Set if the tool button is a toggle button and is toggled on. | ||
State_AutoRaise | Set if the tool button has auto-raise enabled. | ||
State_MouseOver | Set if the mouse pointer is over the tool button. | ||
State_Raised | Set if the button is not down and is not on. | ||
CE_ToolBoxTab | QStyleOptionToolBox | State_Selected | The tab is the currently selected tab. |
CE_HeaderSection | QStyleOptionHeader | State_Sunken | Indicates that the section is pressed. |
State_UpArrow | Indicates that the sort indicator should be pointing up. | ||
State_DownArrow | Indicates 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
)绘制给定的文本。
- 文本使用
painter
的笔绘制,并根据指定的对齐方式进行对齐和换行。 - 如果指定了明确的文本角色(
textRole
),则使用调色板中该角色的颜色绘制文本。 - 启用参数(
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 Element | QStyleOption Subclass | Style Flag | Remark |
---|---|---|---|
PE_FrameFocusRect | QStyleOptionFocusRect | State_FocusAtBorder | Whether the focus is is at the border or inside the widget. |
PE_IndicatorCheckBox | QStyleOptionButton | State_NoChange | Indicates a "tri-state" checkbox. |
State_On | Indicates the indicator is checked. | ||
PE_IndicatorRadioButton | QStyleOptionButton | State_On | Indicates that a radio button is selected. |
State_NoChange | Indicates a "tri-state" controller. | ||
State_Enabled | Indicates the controller is enabled. | ||
PE_IndicatorBranch | QStyleOption | State_Children | Indicates that the control for expanding the tree to show child items, should be drawn. |
State_Item | Indicates that a horizontal branch (to show a child item), should be drawn. | ||
State_Open | Indicates that the tree branch is expanded. | ||
State_Sibling | Indicates that a vertical line (to show a sibling item), should be drawn. | ||
PE_IndicatorHeaderArrow | QStyleOptionHeader | State_UpArrow | Indicates that the arrow should be drawn up; otherwise it should be down. |
PE_FrameGroupBox, PE_Frame, PE_FrameLineEdit, PE_FrameMenu, PE_FrameDockWidget, PE_FrameWindow | QStyleOptionFrame | State_Sunken | Indicates that the Frame should be sunken. |
PE_IndicatorToolBarHandle | QStyleOption | State_Horizontal | Indicates that the window handle is horizontal instead of vertical. |
PE_IndicatorSpinPlus, PE_IndicatorSpinMinus, PE_IndicatorSpinUp, PE_IndicatorSpinDown, | QStyleOptionSpinBox | State_Sunken | Indicates that the button is pressed. |
PE_PanelButtonCommand | QStyleOptionButton | State_Enabled | Set if the button is enabled. |
State_HasFocus | Set if the button has input focus. | ||
State_Raised | Set if the button is not down, not on and not flat. | ||
State_On | Set if the button is a toggle button and is toggled on. | ||
State_Sunken | Set 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_LayoutHorizontalSpacing
或PM_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)的值。
指定的option
和widget
可以用于计算该度量。一般来说,widget
参数不使用。可以使用qstyleoption_cast()
函数将option
转换为适当的类型。
请注意,即使对于可以使用的PixelMetrics
,option
也可能为零。请参见下表了解适当的option转换:
Pixel Metric | QStyleOption Subclass |
---|---|
PM_SliderControlThickness | QStyleOptionSlider |
PM_SliderLength | QStyleOptionSlider |
PM_SliderTickmarkOffset | QStyleOptionSlider |
PM_SliderSpaceAvailable | QStyleOptionSlider |
PM_ScrollBarExtent | QStyleOptionSlider |
PM_TabBarTabOverlap | QStyleOptionTab |
PM_TabBarTabHSpace | QStyleOptionTab |
PM_TabBarTabVSpace | QStyleOptionTab |
PM_TabBarBaseHeight | QStyleOptionTab |
PM_TabBarBaseOverlap | QStyleOptionTab |
一些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;
返回由指定的option
和type
描述的元素的大小,基于提供的contentsSize
。
option参数是指向QStyleOption
或其子类之一的指针。可以使用qstyleoption_cast()
函数将option转换为适当的类型。
widget
是一个可选参数,可以包含用于计算大小的额外信息。
请参见下表了解适当的option转换:
Contents Type | QStyleOption Subclass |
---|---|
CT_CheckBox | QStyleOptionButton |
CT_ComboBox | QStyleOptionComboBox |
CT_GroupBox | QStyleOptionGroupBox |
CT_HeaderSection | QStyleOptionHeader |
CT_ItemViewItem | QStyleOptionViewItem |
CT_LineEdit | QStyleOptionFrame |
CT_MdiControls | QStyleOptionComplex |
CT_Menu | QStyleOption |
CT_MenuItem | QStyleOptionMenuItem |
CT_MenuBar | QStyleOptionMenuItem |
CT_MenuBarItem | QStyleOptionMenuItem |
CT_ProgressBar | QStyleOptionProgressBar |
CT_PushButton | QStyleOptionButton |
CT_RadioButton | QStyleOptionButton |
CT_ScrollBar | QStyleOptionSlider |
CT_SizeGrip | QStyleOption |
CT_Slider | QStyleOptionSlider |
CT_SpinBox | QStyleOptionSpinBox |
CT_Splitter | QStyleOption |
CT_TabBarTab | QStyleOptionTab |
CT_TabWidget | QStyleOptionTabWidgetFrame |
CT_ToolButton | QStyleOptionToolButton |
另请参见 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 Element | QStyleOption Subclass |
---|---|
SE_PushButtonContents | QStyleOptionButton |
SE_PushButtonFocusRect | QStyleOptionButton |
SE_PushButtonBevel | QStyleOptionButton |
SE_CheckBoxIndicator | QStyleOptionButton |
SE_CheckBoxContents | QStyleOptionButton |
SE_CheckBoxFocusRect | QStyleOptionButton |
SE_RadioButtonIndicator | QStyleOptionButton |
SE_RadioButtonContents | QStyleOptionButton |
SE_RadioButtonFocusRect | QStyleOptionButton |
SE_ComboBoxFocusRect | QStyleOptionComboBox |
SE_ProgressBarGroove | QStyleOptionProgressBar |
SE_ProgressBarContents | QStyleOptionProgressBar |
SE_ProgressBarLabel | QStyleOptionProgressBar |
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::AlignAbsolute
的Qt::AlignLeft
或Qt::AlignRight
对齐方式转换为带Qt::AlignAbsolute
的Qt::AlignLeft
或Qt::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。