Qt 样式表参考
Qt 样式表支持各种属性、伪状态和子控件,可以自定义 widgets 的外观。
可风格化部件列表
下表列出了可使用样式表自定义的 Qt 部件:
部件 | 样式 |
---|---|
QAbstractScrollArea | 支持盒装模式 All derivatives of QAbstractScrollArea, including QTextEdit, and QAbstractItemView (all item view classes), support scrollable backgrounds using background-attachment. Setting the background-attachment to fixed provides a background-image that does not scroll with the viewport. Setting the background-attachment to scroll , scrolls the background-image when the scroll bars move. 有关示例,请参阅定制 QAbstractScrollArea。 |
QCheckBox | 支持方框模型。可使用::indicator子控件对复选指示器进行样式设置。默认情况下,指示器位于窗口小部件内容矩形的左上角。 间距属性指定复选指示器与文本之间的间距。 有关示例,请参阅自定义 QCheckBox。 |
QColumnView | 可以使用图像属性来设计握柄的样式。 箭头指示器的样式可使用::左箭头子控件和::右箭头子控件。 |
QComboBox | 组合框周围的框架可以使用框模型来设计。 下拉按钮可以使用::drop-down子控件进行样式设置。默认情况下,下拉按钮位于 widget 填充矩形的右上角。 下拉按钮内的箭头标记可以使用::向下箭头子控件进行样式设置。默认情况下,箭头位于下拉子控件内容矩形的中心。 可使用placeholder-text-color属性设置占位符文本的颜色。 有关示例,请参阅自定义 QComboBox。 |
QDateEdit | 请参见QSpinBox。 |
QDateTimeEdit | 请参见QSpinBox。 |
QDialog | 仅支持background、background-clip和background-origin属性。 警告: 请确保您为自定义 widget 定义了Q_OBJECT 宏。 |
QDialogButtonBox | 可使用按钮布局属性更改按钮布局。 |
QDockWidget | 支持停靠时标题栏和标题栏按钮的样式。 可使用border属性设置停靠 widget 边框的样式。title子控件可用于自定义标题栏。关闭按钮和浮动按钮分别使用::close-button和::float-button与:: title子控件相对定位。 当标题栏垂直时,将设置:vertical伪类。此外,根据QDockWidget::DockWidgetFeature ,还将设置:closedable、:floatable和:movable伪状态。 注意: 使用 QMainWindow::separator 来样式化调整大小句柄。 警告: 当QDockWidget 取消锁定时,样式表没有任何作用,因为 Qt XML 在取消锁定时使用的是原生的顶层窗口。 有关示例,请参阅自定义 QDockWidget。 |
QDoubleSpinBox | 请参见QSpinBox。 |
QFrame | 支持盒模型。 Since 4.3, setting a stylesheet on a QLabel automatically sets the QFrame::frameStyle property to QFrame::StyledPanel. 有关示例,请参阅自定义 QFrame。 |
QGroupBox | 支持方框模型。 标题可使用::title子控件进行样式设置。默认情况下,标题的位置取决于 QGroupBox::textAlignment. In the case of a checkable QGroupBox, the title includes the check indicator. The indicator is styled using the ::indicator subcontrol. The spacing property can be used to control the spacing between the text and indicator. 有关示例,请参阅定制 QGroupBox。 |
QHeaderView | 支持框模型。 标题视图的各部分使用::section子控件进行样式设置。 section 子控件支持:middle、:first、:last、:only-one、:next-selected、:previous-selected、: selected 和:checked伪状态。可使用::up-arrow和::down-arrow子控件对排序指示符进行样式设置。 有关示例,请参阅自定义 QHeaderView。 |
QLabel | 支持方框模型。不支持:hover伪状态。 Since 4.3, setting a stylesheet on a QLabel automatically sets the QFrame::frameStyle property to QFrame::StyledPanel. 有关示例,请参阅 "自定义 QFrame"(QLabel 源自QFrame )。 |
QLineEdit | 支持框模型。 选中项的颜色和背景分别使用selection-color和selection-background-color进行样式设置。 可使用placeholder-text-color属性设置占位符文本的颜色。 密码字符可以使用lineedit-password-character属性进行样式设置。 密码掩码延迟可使用lineedit-password-mask-delay 进行更改,示例请参见定制 QLineEdit。 |
QListView | 支持方框模型。 When alternating row colors is enabled, the alternating colors can be styled using the alternate-background-color property. 选中项的颜色和背景分别使用selection-color和selection-background-color进行样式设计。 选择行为由show-decoration-selected属性控制。 使用::item子控件可对QListView 中的项目进行更精细的控制。 请参阅QAbstractScrollArea来设计滚动背景。 有关示例,请参见自定义 QListView。 |
QListWidget | 请参见QListView。 |
QMainWindow | 支持分隔符样式。 The separator in a QMainWindow when using QDockWidget is styled using the ::separator subcontrol. 有关示例,请参阅定制 QMainWindow。 |
QMenu | 支持盒模型。 单个项目的样式使用::item子控件。除了通常支持的伪状态外, item 子控件还支持:selected、:default、:exclusive和non-exclusive伪状态。可选中菜单项的指示符使用::indicator子控件样式化。 分隔符的样式使用::separator子控件。 对于有子菜单的项目,箭头标记的样式使用右箭头和左箭头。 滚动条的样式使用::scroller。 下拉菜单使用::下拉菜单样式。 有关示例,请参阅自定义 QMenu。 |
QMenuBar | 支持方框模型。 间距属性指定菜单项之间的间距。单个项目的样式使用::item子控件。 警告 在 Qt/Mac 上运行时,菜单栏通常嵌入到系统范围的菜单栏中。在这种情况下,样式表将不起作用。 有关示例,请参阅自定义 QMenuBar。 |
QMessageBox | messagebox-text-interaction-flags属性可用于改变与消息框中文本的交互。 |
QProgressBar | 支持方框模型。 进度条的分块可使用::chunk子控件进行样式设置。该块显示在 widget 的内容矩形上。 如果进度条显示文本,可使用text-align属性定位文本。 不确定进度条具有:indeterminate伪状态设置。 有关示例,请参阅自定义 QProgressBar。 |
QPushButton | 支持方框模型。 支持:default、:flat 和:checked伪状态。 自 5.15 版起,可设置图标属性以覆盖按钮图标。 For QPushButton with a menu, the menu indicator is styled using the ::menu-indicator subcontrol. Appearance of checkable push buttons can be customized using the :open and :closed pseudo-states. 警告: 如果只在QPushButton 上设置背景色,除非将 border 属性设置为某个值,否则背景可能不会显示。这是因为,默认情况下,QPushButton 会绘制一个与背景色完全重叠的本地边框。例如 QPushButton { background-color: red; border: none; } 有关示例,请参阅自定义 QPushButton。 |
QRadioButton | 支持方框模型。 可使用::indicator子控件对复选指示器进行样式设置。默认情况下,指示器位于窗口小部件内容矩形的左上角。 间距属性用于指定校验指示器与文本之间的间距。 有关示例,请参阅自定义 QRadioButton。 |
QScrollBar | 支持方框模型。 The Contents rectangle of the widget is considered to be the groove over which the slider moves. The extent of the QScrollBar (i.e the width or the height depending on the orientation) is set using the width or height property respectively. To determine the orientation, use the :horizontal and the :vertical pseudo states. 可以使用::handle子控件对滑块进行样式设置。设置最小宽度或最小高度可根据方向限制滑块的尺寸。 ::add-line子控件可用于为按钮添加一行样式。默认情况下,add-line 子控件位于 widget 边框矩形的右上角。根据方向的不同,可以使用::右箭头或::下箭头。默认情况下,箭头位于添加行子控件内容矩形的中心。 子行子控件可用于设置减行按钮的样式。默认情况下,子行子控件位于 widget 边框矩形的右下角。根据方向的不同,可以使用: : 左箭头或::上箭头。默认情况下,箭头位于子行子控件内容矩形的中心。 子页面子控件可用于样式化滑块的减页区域。add-page子控件可用于样式化滑块中添加页面的区域。 有关示例,请参阅自定义 QScrollBar。 |
QSizeGrip | 支持宽度、高度和图像属性。 有关示例,请参阅自定义 QSizeGrip。 |
QSlider | 支持盒模型。 对于水平滑动条,必须提供最小宽度和高度属性。对于垂直滑块,必须提供最小高度和宽度属性。 滑块的凹槽使用::groove 定型。凹槽默认位于 widget 的内容矩形内。滑块的拇指使用::handle子控件进行样式设置。该子控件在凹槽子控件的内容矩形中移动。 有关示例,请参阅自定义 QSlider。 |
QSpinBox | 旋转框的边框可使用框模型进行样式设计。 向上按钮和箭头可以使用::up-button和::up-arrow子控件进行样式设置。默认情况下,向上按钮位于 widget 的右上角,在 Padding 矩形中。在没有明确尺寸的情况下,它占据参考矩形高度的一半。向上箭头位于向上按钮内容矩形的中心。 下拉按钮和箭头可以使用::down-button和::down-arrow子控件进行样式设置。默认情况下,向下按钮位于 widget 的右下角 "填充 "矩形中。在没有明确尺寸的情况下,它占据参考矩形高度的一半。底部箭头位于底部按钮内容矩形的中心。 有关示例,请参阅自定义 QSpinBox。 |
QSplitter | 支持框模型。分割器的句柄使用::handle子控件进行样式设置。 有关示例,请参阅自定义 QSplitter。 |
QStatusBar | 仅支持背景属性。单个项目的框架可使用::item子控件设置样式。 有关示例,请参阅定制 QStatusBar。 |
QTabBar | 可使用::tab子控件设置单个选项卡的样式。使用::close-button关闭按钮。标签支持:only-one、:first、:last、:middle、:previous-selected、: next-selected、:selected 伪状态。 根据标签页的方向,支持:top、: left、:right、:bottom 伪状态。 Overlapping tabs for the selected state are created by using negative margins or using the absolute position scheme. The tear indicator of the QTabBar is styled using the ::tear subcontrol. QTabBar used two QToolButtons for its scrollers that can be styled using the QTabBar QToolButton selector. To specify the width of the scroll button use the ::scroller subcontrol. The alignment of the tabs within the QTabBar is styled using the alignment property. 警告: 要更改QTabBar 在QTabWidget 中的位置,请使用制表符栏子控件(并设置子控件位置)。 有关示例,请参阅自定义 QTabBar。 |
QTabWidget | 使用::pane子控件可对选项卡 widget 的边框进行样式设置。左角和右角分别使用::left-corner和::right-corner进行样式设置。标签栏的位置由::tab-bar子控件控制。 By default, the subcontrols have positions of a QTabWidget in the QWindowsStyle. To place the QTabBar in the center, set the subcontrol-position of the tab-bar subcontrol. :top、:left、:right、:bottom 伪状态取决于标签页的方向。 有关示例,请参阅自定义 QTabWidget。 |
QTableView | 支持方框模型。启用alternating row colors 后,可使用alternate-background-color属性设计交替颜色。 选中项的颜色和背景可分别使用selection-color和selection-background-color进行样式设置。 The corner widget in a QTableView is implemented as a QAbstractButton and can be styled using the "QTableView QTableCornerButton::section" selector. 警告: 如果只在 QTableCornerButton 上设置背景色,除非将 border 属性设置为某个值,否则背景可能不会显示。这是因为默认情况下,QTableCornerButton 会绘制一个与背景色完全重叠的本地边框。
|
QTableWidget | 请参见QTableView。 |
QTextEdit | 支持框模型。 选中文本的颜色和背景分别使用selection-color和selection-background-color进行样式设置。 可使用placeholder-text-color属性设置占位符文本的颜色。 请参阅QAbstractScrollArea以设置可滚动背景的样式。 |
QTimeEdit | 请参见QSpinBox。 |
QToolBar | 支持方框模型。 :top、:left、:right、:bottom伪状态取决于工具栏分组的区域。 :first、:last、:middle、:only-one伪状态指示工具栏在线条组中的位置(参见QStyleOptionToolBar::positionWithinLine )。 The separator of a QToolBar is styled using the ::separator subcontrol. 句柄(用于移动工具栏)使用::handle子控件样式化。 有关示例,请参阅自定义 QToolBar。 |
QToolButton | 支持方框模型。 If the QToolButton has a menu, is ::menu-indicator subcontrol can be used to style the indicator. By default, the menu-indicator is positioned at the bottom right of the Padding rectangle of the widget. If the QToolButton is in QToolButton::MenuButtonPopup mode, the ::menu-button subcontrol is used to draw the menu button. ::menu-arrow subcontrol is used to draw the menu arrow inside the menu-button. By default, it is positioned in the center of the Contents rectangle of the menu-button subcontrol. When the QToolButton displays arrows, the ::up-arrow, ::down-arrow, ::left-arrow and ::right-arrow subcontrols are used. 警告: 如果只在QToolButton 上设置背景颜色,除非将 border 属性设置为某个值,否则背景将不会显示。这是因为,默认情况下,QToolButton 会绘制一个与背景色完全重叠的本地边框。例如 QToolButton { background-color: red; border: none; } 有关示例,请参阅自定义 QToolButton。 |
QToolBox | 支持方框模型。 可使用::tab子控件对单个选项卡进行样式设置。标签支持:only-one、:first、:last、:middle、:previous-selected、: next-selected、:selected 伪状态。 |
QToolTip | 支持方框模型。不透明度属性控制工具提示的不透明度。 有关示例,请参阅自定义 QFrame(QToolTip 是QFrame )。 |
QTreeView | 支持方框模型。启用alternating row colors 后,可使用alternate-background-color属性设计交替颜色。 选中项的颜色和背景可分别使用selection-color和selection-background-color进行样式设置。 选择行为由show-decoration-selected属性控制。 可以使用::分支子控件对树视图的分支进行样式设置。分支子控件支持 :open、:close、:has-sibling和:has-children伪状态。 使用::item子控件可对QTreeView 中的项目进行更精细的控制。 请参阅QAbstractScrollArea来样式化滚动背景。 请参阅自定义 QTreeView以了解分支样式的示例。 |
QTreeWidget | 请参见QTreeView。 |
QWidget | 仅支持background、background-clip和background-origin属性。 If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below: void CustomWidget::paintEvent(QPaintEvent *) { QStyleOptionopt; opt.initFrom(this); QPainterp(this); style()->drawPrimitive(QStyle::PE_Widget, &opt,&p, this); } 如果没有设置样式表,上述代码将无法运行。 警告: 请确保您为自定义 widget 定义了Q_OBJECT 宏。 |
属性列表
本节列出了 Qt 样式表支持的所有属性。属性的值取决于属性的类型。除非另有说明,否则以下属性适用于所有部件。标有星号 * 的属性是 Qt 特有的,在 CSS2 或 CSS3 中没有对应的属性。以下是 Qt 特有的属性:
- 网格线颜色
- 图像
- 行编辑密码字符
- 行编辑-密码-掩码-延迟
- 消息框-文本-交互标记* 不透明
- 不透明度
- 占位符文本颜色
- 选择-背景-颜色
- 选择颜色
- 显示已选装饰
- 间距
- 子控件-原点
- 子控件位置
- widget-animation-duration
重音颜色
类型 | 画笔 |
该属性设置Accent
,用于强调交互式用户界面元素。如果未设置该属性,则默认为highlight
颜色。
备用背景色
类型 | 笔刷 |
QAbstractItemView 子类中使用的alternate background color 。
如果未设置该属性,默认值就是调色板AlternateBase 角色的设置值。
示例
QTreeView { alternate-background-color: blue; background: yellow; }
另请参阅background和selection-background-color。
背景
类型 | 背景 |
设置背景的速记符号。等同于指定background-color
,background-image
,background-repeat
, 和/或background-position
。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QDialog,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit,QToolTip, 和普通QWidgets 支持此属性。
举例说明:
QTextEdit { background: yellow }
通常情况下,需要设置与Qt::BrushStyle 中的样式类似的填充样式。您可以为Qt::SolidPattern,Qt::RadialGradientPattern,Qt::LinearGradientPattern 和Qt::ConicalGradientPattern 使用 background-color 属性。创建包含图案的背景图片即可轻松实现其他图案。
示例
QLabel { background-image: url(dense6pattern.png); background-repeat: repeat-xy; }
另请参阅background-origin、selection-background-color、background-clip、background-attachment和alternate-background-color。
背景颜色
类型 | 画笔 |
用于 widget 的背景颜色。
例如
background-image
类型 | 网址 |
用于 widget 的背景图片。图片的半透明部分让background-color
露出来。
例如
QFrame { background-image: url(:/images/hydro.png) }
背景重复
类型 | 重复 |
背景图片是否以及如何重复填充background-origin
矩形。
如果未指定此属性,背景图片将在两个方向上重复 (repeat
)。
示例
QFrame { background: white url(:/images/ring.png); background-repeat: repeat-y; background-position: left; }
background-position
类型 | 对齐方式 |
背景图片在background-origin
矩形内的对齐方式。
如果未指定此属性,则对齐方式为top
left
。
举例说明:
QFrame { background: url(:/images/footer.png); background-position: bottom left; }
background-attachment
类型 | 附件 |
确定QAbstractScrollArea 中的背景图片相对于视口是滚动还是固定。默认情况下,背景图片随视口滚动。
示例
QTextEdit { background-image: url("leaves.png"); background-attachment: fixed; }
另请参阅背景
背景-剪辑
类型 | 起源 |
部件的矩形,在其中绘制background
。
该属性指定了background-color
和background-image
所剪切的矩形。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QDialog,QFrame,QGroupBox,QLabel,QPushButton,QRadioButton,QSplitter,QTextEdit,QToolTip, 和普通QWidget均支持此属性。
如果未指定此属性,默认值为border
。
示例
QFrame { background-image: url(:/images/header.png); background-position: top left; background-origin: content; background-clip: padding; }
另请参阅background、background-origin和The Box Model。
背景-原点
类型 | 原点 |
widget 的背景矩形,与background-position
和background-image
结合使用。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QDialog,QFrame,QGroupBox,QLabel,QPushButton,QRadioButton,QSplitter,QTextEdit,QToolTip, 以及普通QWidgets 均支持该属性。
如果未指定此属性,默认值为padding
。
示例
QFrame { background-image: url(:/images/header.png); background-position: top left; background-origin: content; }
边框
类型 | 边框 |
设置 widget 边框的速记符号。相当于指定border-color
,border-style
, 和/或border-width
。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit,QToolTip, 以及普通QWidgets 均支持此属性。
举例说明:
QLineEdit { border: 1px solid white }
border-top
类型 | 边框 |
设置 widget 顶部边框的速记符号。等同于指定border-top-color
,border-top-style
, 和/或border-top-width
。
右边界
类型 | 边框 |
设置 widget 右边界的速记符号。相当于指定border-right-color
,border-right-style
, 和/或border-right-width
。
边框-底部
类型 | 边框 |
设置 widget 底部边框的速记符号。相当于指定border-bottom-color
,border-bottom-style
, 和/或border-bottom-width
。
左边界
类型 | 边框 |
设置 widget 左边界的速记符号。相当于指定border-left-color
,border-left-style
, 和/或border-left-width
。
边框颜色
类型 | 方框颜色 |
所有边框边缘的颜色。相当于指定border-top-color
,border-right-color
,border-bottom-color
, 和border-left-color
。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit,QToolTip, 和普通QWidgets 均支持此属性。
如果未指定该属性,则默认为color(即 widget 的前景色)。
示例
QLineEdit { border-width: 1px; border-style: solid; border-color: white; }
另请参阅border-style、border- width、border-image 和方框模型。
border-top-color
类型 | 笔刷 |
边框顶部边缘的颜色。
边框右侧颜色
类型 | 笔刷 |
边框右边缘的颜色。
边框底部颜色
类型 | 笔刷 |
边框底边的颜色。
边框左侧颜色
类型 | 笔刷 |
边框左边缘的颜色。
边框图像
类型 | 边框图像 |
用于填充边框的图像。图像会被切成九份,必要时还会适当拉伸。有关详细信息,请参阅边框图像。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit 和QToolTip 支持此属性。
另请参阅border-color、border-style、border- width 和方框模型。
边框半径
类型 | 半径 |
边框边角的半径。相当于指定border-top-left-radius
,border-top-right-radius
,border-bottom-right-radius
, 和border-bottom-left-radius
。
边框半径会剪切元素的背景。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit, 和QToolTip 支持此属性。
如果未指定此属性,默认值为 0。
示例
QLineEdit { border-width: 1px; border-style: solid; border-radius: 4px; }
另请参阅border-width和方框模型。
border-top-left-radius
类型 | 半径 |
边框左上角的半径。
边框右上角半径
类型 | 半径 |
边框右上角的半径。
边框右下角半径
类型 | 半径 |
边框右下角的半径。将此属性设置为正值会产生一个圆角。
边框左下角半径
类型 | 半径 |
边框左下角的半径。如果将此属性设置为正值,则边框会变成圆角。
边框样式
类型 | 边框样式 |
所有边框边缘的样式。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit, 和QToolTip 支持此属性。
如果未指定此属性,则默认为none
。
示例
QLineEdit { border-width: 1px; border-style: solid; border-color: blue; }
另请参阅border-color、border-style、border-image 和方框模型。
border-top-style
类型 | 边框样式} |
边框顶边的样式。
border-right-style
类型 | 边框样式 |
边框右边缘的样式。
边框底部样式
类型 | 边框样式 |
边框底边的样式。
边框左侧样式
类型 | 边框样式 |
边框左边缘的样式。
边框宽度
类型 | 方框长度 |
边框的宽度。相当于设置border-top-width
,border-right-width
,border-bottom-width
, 和border-left-width
。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit, 和QToolTip 支持此属性。
举例说明:
QLineEdit { border-width: 2px; border-style: solid; border-color: darkblue; }
另请参阅border-color、border-radius、border-style、border-image 和方框模型。
border-top-width
类型 | 长度 |
边框顶部边缘的宽度。
border-right-width
类型 | 长度 |
边框右边缘的宽度。
border-bottom-width
类型 | 长度 |
边框底边的宽度。
边框左宽
类型 | 长度 |
边框左边缘的宽度。
底部
类型 | 长度 |
如果position为relative
(默认值),则将子控件向上移动一定偏移量;指定 bottom: y
相当于指定 top: -y
.
如果position为absolute
,则bottom
属性指定子控件的底边与父控件底边的关系(另请参阅子控件-原点)。
示例
QSpinBox::down-button { bottom: 2px }
按钮布局
类型 | 数量 |
QDialogButtonBox 或QMessageBox 中按钮的布局。可能的值为 0 (WinLayout)、1 (MacLayout)、2 (KdeLayout)、3 (GnomeLayout) 和 5 (AndroidLayout)。
如果未指定该属性,则默认为当前样式为SH_DialogButtonLayout 样式提示指定的值。
示例
* { button-layout: 2 }
颜色
类型 | 刷子 |
用于渲染文本的颜色。
所有尊重QWidget::palette 的部件都支持该属性。
如果未设置该属性,则默认为该 widget 的调色板中为QWidget::foregroundRole 设置的颜色(通常为黑色)。
示例
QPushButton { color: red }
对话框按钮有图标
类型 | 布尔值 |
QDialogButtonBox 中的按钮是否显示图标
如果该属性设置为 1,则QDialogButtonBox 的按钮显示图标;如果设置为 0,则不显示图标。
有关如何设置图标的信息,请参阅图标列表部分。
QDialogButtonBox { dialogbuttonbox-buttons-have-icons: 1; }
注意: 必须在创建QDialogButtonBox 之前应用定义此属性的样式;这意味着必须将样式应用到父窗口部件或应用程序本身。
字体
类型 | 字体 |
设置文本字体的速记符号。等同于指定font-family
,font-size
,font-style
, 和/或font-weight
。
所有尊重QWidget::font 的部件都支持该属性。
如果未设置此属性,则默认为QWidget::font 。
示例
QCheckBox { font: bold italic large "Times New Roman" }
font-family
类型 | 字符串 |
字体家族。
例如
QCheckBox { font-family: "New Century Schoolbook" }
font-size
类型 | 字体大小 |
字体大小。在此版本的 Qt 中,仅支持 pt 和 px 度量。
例如
QTextEdit { font-size: 12px }
font-style
字体类型 | 字体样式 |
字体样式。
例如
QTextEdit { font-style: italic }
font-weight
类型 | 字体重量 |
字体的重量。
网格线颜色
类型 | 颜色 |
QTableView 中网格线的颜色。
如果未指定此属性,则默认为当前样式为SH_Table_GridLineColor 样式提示指定的值。
示例
* { gridline-color: gray }
高度
类型 | 长度 |
子控件(有时是 widget)的高度。
如果未指定该属性,默认值取决于子控件/部件和当前样式。
警告 除非另有规定,否则该属性在部件上设置时无效。如果您想要一个固定高度的 widget,请将min-height和max-height设置为相同的值。
示例
QSpinBox::down-button { height: 10px }
另请参阅宽度。
图标
类型 | Url+ |
用于有图标的部件的图标。
目前唯一支持该属性的 widget 是QPushButton 。
注意: 为按钮分配图标是应用程序的责任(使用QAbstractButton API),而不是样式的责任。因此,除非您的样式表是针对特定应用程序的,否则请谨慎设置。
自 5.15 版起可用。
图标大小
类型 | 长度 |
widget 中图标的宽度和高度。
以下 widget 的图标大小可使用此属性设置。
图像*
类型 | Url+ |
绘制在子控件内容矩形中的图像。
image 属性可接受一个Urls列表或一个svg
。实际绘制的图像将使用与QIcon 相同的算法确定(即图像永远不会放大,但在必要时会缩小)。如果指定了svg
,图像将按内容矩形的大小缩放。
在子控件上设置图像属性会隐式设置子控件的宽度和高度(除非图像是 SVG)。
在 Qt 4.3 及更高版本中,可使用image-position 指定矩形内图像的对齐方式。
该属性仅适用于子控件,其他元素不支持该属性。
警告: 渲染 SVG 图像需要QIcon SVG 插件。
举例说明:
// implicitly sets the size of down-button to the // size of spindown.png QSpinBox::down-button { image: url(:/images/spindown.png) }
图像位置
类型 | 对齐 |
在 Qt Positioning 4.3 及更高版本中,可使用相对位置或绝对位置指定图像图片位置的对齐方式。
左对齐
类型 | 长度 |
如果position为relative
(默认值),则将子控件向右移动一定偏移量。
如果position为absolute
,则left
属性指定子控件相对于父控件左边缘的左边缘(另请参阅subcontrol-origin)。
如果未指定该属性,则默认为0
。
示例
QSpinBox::down-button { left: 2px }
字母间距
类型 | 长度 |
部件中字符串的字符间距。
lineedit-password-character* 行编辑密码字符
类型 | 数字 |
QLineEdit 密码字符的 Unicode 数字。
如果未指定此属性,则默认为当前样式为SH_LineEdit_PasswordCharacter 样式提示指定的值。
示例
* { lineedit-password-character: 9679 }
lineedit-password-mask-delay* 行编辑密码掩码延迟
类型 | 数量 |
QLineEdit 在lineedit-password 字符应用于可见字符前的密码掩码延迟(毫秒)。
如果未指定此属性,则默认为当前样式为SH_LineEdit_PasswordMaskDelay 样式提示指定的值。
自 Qt 5.4 起可用。
示例
* { lineedit-password-mask-delay: 1000 }
边距
类型 | 方框长度 |
部件的边距。相当于指定margin-top
,margin-right
,margin-bottom
, 和margin-left
。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit, 和QToolTip 支持此属性。
如果未指定此属性,则默认为0
。
示例
QLineEdit { margin: 2px }
另请参阅padding、spacing 和The Box Model。
margin-top
类型 | 长度 |
widget 的顶部边距。
margin-right
类型 | 长度 |
widget 的右边距。
margin-bottom
类型 | 长度 |
widget 的底部边距。
margin-left
类型 | 长度 |
widget 的左边距。
最大高度
类型 | 长度 |
部件或子控件的最大高度。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSizeGrip,QSpinBox,QSplitter,QStatusBar,QTextEdit, 和QToolTip 支持此属性。
该值是相对于方框模型中的内容矩形而言的。
举例说明:
QSpinBox { max-height: 24px }
另请参阅max-width。
max-width
类型 | 长度 |
部件或子控件的最大宽度。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSizeGrip,QSpinBox,QSplitter,QStatusBar,QTextEdit, 和QToolTip 支持此属性。
该值是相对于方框模型中的内容矩形而言的。
举例说明:
QComboBox { max-width: 72px }
另请参阅max-height。
消息框-文本-交互标记*(messagebox-text-interaction-flags
类型 | 数量 |
消息框中文本的交互行为。可能的值基于Qt::TextInteractionFlags 。
如果未指定该属性,则默认为当前样式为SH_MessageBox_TextInteractionFlags 样式提示指定的值。
示例
QMessageBox { messagebox-text-interaction-flags: 5 }
最小高度
类型 | 长度 |
部件或子控件的最小高度。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSizeGrip,QSpinBox,QSplitter,QStatusBar,QTextEdit,QToolButton, 和QToolTip 支持此属性。
如果未指定此属性,则根据 widget 的内容和样式得出最小高度。
该值相对于方框模型中的内容矩形。
示例
QComboBox { min-height: 24px }
注意: 设置此属性可能会使窗口小部件的收缩空间小于内容所需的空间。
另请参阅min-width。
最小宽度
类型 | 长度 |
部件或子控件的最小宽度。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSizeGrip,QSpinBox,QSplitter,QStatusBar,QTextEdit,QToolButton, 和QToolTip 支持此属性。
如果未指定此属性,则根据部件的内容和样式得出最小宽度。
该值相对于方框模型中的内容矩形。
示例
QComboBox { min-width: 72px }
注意: 设置此属性可能会使窗口小部件的收缩空间小于内容所需的空间。
另请参阅最小高度。
不透明度
类型 | 数值 |
部件的不透明度。可能的值从 0(透明)到 255(不透明)。目前,只有tooltips 支持此功能。
如果未指定该属性,则默认为当前样式为SH_ToolTipLabel_Opacity 样式提示指定的值。
示例
QToolTip { opacity: 223 }
概述
围绕对象边界绘制的轮廓。
轮廓颜色
类型 | 颜色 |
轮廓的颜色。另请参阅边框颜色
轮廓偏移
类型 | 长度 |
轮廓与 widget 边界的偏移量。
轮廓样式
指定用于绘制轮廓的样式。另请参阅border-style
轮廓半径
为轮廓添加圆角。
大纲-左下角-半径
类型 | 半径 |
轮廓左下角圆角的半径。
轮廓右下角半径
类型 | 半径 |
轮廓右下角圆角的半径。
大纲左上角半径
类型 | 半径 |
轮廓左上角的半径。
轮廓右上角半径
类型 | 半径 |
轮廓右上角圆角的半径。
填充
类型 | 方框长度 |
部件的填充。相当于指定padding-top
,padding-right
,padding-bottom
, 和padding-left
。
QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit, 和QToolTip 支持此属性。
如果未指定此属性,则默认为0
。
示例
QLineEdit { padding: 3px }
另请参阅margin、spacing 和The Box Model。
padding-top
类型 | 长度 |
widget 顶部的 padding。
padding-right
类型 | 长度 |
widget 的右边填充。
padding-bottom
类型 | 长度 |
widget 底部的 padding。
padding-left
类型 | 长度 |
widget 的左填充。
paint-alternating-row-colors-for-empty-area (为空区域绘制替代行颜色
类型 | bool |
QTreeView 是否为空白区域(即没有项目的区域)绘制交替行颜色
占位符文本颜色
类型 | 画笔 |
文本编辑 widget 的占位符文本使用的颜色。
如果未设置该属性,默认值就是调色板PlaceholderText 角色的设置值。
示例
QLineEdit { placeholder-text-color: #800000ff } /* semi-transparent blue */
自 6.5 版起可用。
位置
类型 | relative | absolute |
如果未指定该属性,默认值为relative
。
右
类型 | 长度 |
如果position为relative
(默认值),则将子控件向左移动一定偏移量;指定 right: x
相当于指定 left: -x
.
如果position为absolute
,则right
属性将指定子控件相对于父控件右边缘的右边缘(另请参阅子控件-原点)。
示例
QSpinBox::down-button { right: 2px }
选择-背景-颜色*
类型 | 笔刷 |
选定文本或项目的背景。
所有尊重QWidget::palette 并显示选中文本的部件都支持该属性。
如果未设置该属性,默认值就是为调色板Highlight 角色设置的值。
示例
QTextEdit { selection-background-color: darkblue }
另请参阅selection-color和background。
selection-color*
类型 | 画笔 |
选中文本或项目的前景色。
所有尊重QWidget::palette 并显示选中文本的 widget 都支持该属性。
如果未设置该属性,默认值就是为调色板HighlightedText 角色设置的值。
示例
QTextEdit { selection-color: white }
另请参阅selection-background-color和color。
show-decoration-selected* 显示已选装饰
类型 | 布尔 |
控制QListView 中的选择是否覆盖整行或仅覆盖文本范围。
如果未指定该属性,则默认为当前样式为SH_ItemView_ShowDecorationSelected 样式提示指定的值。
示例
* { show-decoration-selected: 1 }
间距*
类型 | 长度 |
部件的内部间距。
QCheckBox 、可选中的QGroupBoxes、QMenuBar 和QRadioButton 支持此属性。
如果未指定该属性,默认值取决于 widget 和当前样式。
示例
QMenuBar { spacing: 10 }
子控件源文件*
类型 | 原点 |
子控件在父元素中的原点矩形。
如果未指定该属性,默认值为padding
。
示例
QSpinBox::up-button { image: url(:/images/spinup.png); subcontrol-origin: content; subcontrol-position: right top; }
另请参阅subcontrol-position。
子控制位置*
类型 | 对齐方式 |
子控件在由subcontrol-origin 指定的原点矩形内的对齐方式。
如果未指定该属性,默认值取决于子控件。
例如
QSpinBox::down-button { image: url(:/images/spindown.png); subcontrol-origin: padding; subcontrol-position: right bottom; }
另请参阅subcontrol-origin。
标题栏-按钮上显示工具提示
类型 | bool |
是否在窗口标题栏按钮上显示工具提示。
小部件动画持续时间*
类型 | 数量 |
动画应持续的时间(以毫秒为单位)。数值等于零表示将禁用动画。
如果未指定此属性,则默认为当前样式为SH_Widget_Animation_Duration 样式提示指定的值。
自 Qt 5.10 起可用。
示例
* { widget-animation-duration: 100 }
text-align
类型 | 对齐方式 |
文字和图标在 widget 内容中的对齐方式。
如果未指定该值,则默认为取决于本地样式的值。
例如
QPushButton { text-align: left; }
目前只有QPushButton 和QProgressBar 支持此属性。
文字修饰
类型 | none underline overline line-through |
附加文字效果
顶部
类型 | 长度 |
如果position为relative
(默认值),则将子控件向下移动一定偏移量。
如果position为absolute
,则top
属性指定子控件相对于父控件顶边的顶边(另请参阅子控件-原点)。
如果未指定该属性,则默认为0
。
示例
QSpinBox::up-button { top: 2px }
宽度
类型 | 长度 |
子控件(或某些情况下的 widget)的宽度。
如果未指定该属性,默认值取决于子控件/部件和当前样式。
例如
QSpinBox::up-button { width: 12px }
另请参阅height。
字距
类型 | 长度 |
widget 中字符串中每个单词之间的间距。
-qt-background-role
类型 | 调色板角色 |
基于所选角色的子控件或 widget 的background-color
。
-qt-style-features
类型 | list |
要应用 Qt 特定样式的 CSS 属性列表。
注意: list
只能包含不基于像素图的属性。
图标列表
Qt 中使用的图标可通过以下属性进行自定义。本节列出的每个属性都有图标类型。
请注意,要在QDialogButtonBox 中的按钮中显示图标,需要将 dialogbuttonbox-buttons-have-icons 属性设置为 true。此外,要自定义图标的大小,请使用图标大小属性。
属性类型列表
下表概述了不同属性类型的语法和含义。
类型 | 语法 | 说明 |
---|---|---|
对齐 | {top | bottom | left | right | center }* | Horizontal and/or vertical alignment. Example: QTextEdit { background-position: bottom center } |
附件 | {scroll | fixed }* | Scroll or fixed attachment. |
背景 | {画笔 |网址 |重复 |对齐}* | 刷子、Url、重复和排列的序列。 |
布尔值 | 0 | 1 | 真(1 )或假(0 )。举例说明: QDialog { etch-disabled-text: 1 } |
边框 | {边框样式 |长度 |笔刷}* | 速记边框属性。 |
边框图像 | none |Url Number{4} ( stretch | repeat ){0,2} | A border image is an image that is composed of nine parts (top left, top center, top right, center left, center, center right, bottom left, bottom center, and bottom right). When a border of a certain size is required, the corner parts are used as is, and the top, right, bottom, and left parts are stretched or repeated to produce a border with the desired size. See the CSS3 Draft Specification for details. |
边框样式 | dashed | dot-dash | dot-dot-dash | dotted | double | groove | inset | outset | ridge | solid | none | Specifies the pattern used to draw a border. See the CSS3 Draft Specification for details. |
方框颜色 | 画笔{1,4} | 一至四次刷色,分别指定方框的顶部、右侧、底部和左侧边缘。如果未指定左侧颜色,则认为与右侧颜色相同。如果未指定底部颜色,则认为它与顶部颜色相同。如果没有指定右边的颜色,则认为它与上边的颜色相同。 示例 |
方框长度 | 长度{1,4} | 一至四个Length,分别指定方框的顶部、右侧、底部和左侧边缘。如果未指定左侧长度,则视为与右侧长度相同。如果未指定底部长度,则视为与顶部长度相同。如果未指定右边长度,则认为它与上边长度相同。 示例 |
画笔 | 颜色 |梯度 |调色板作用 | 指定颜色、渐变或调色板中的条目。 |
颜色 | rgb(r, g, b) | rgba(r, g, b, a) | hsv(h, s, v) | hsva(h, s, v, a) | hsl(h, s, l) | hsla(h, s, l, a) | #rrggbb | Color Name | 将颜色指定为 RGB(红、绿、蓝)、RGBA(红、绿、蓝、alpha)、HSV(色相、饱和度、值)、HSVA(色相、饱和度、值、alpha)、HSL(色相、饱和度、明度)、HSLA(色相、饱和度、明度、alpha)或已命名的颜色。rgb() 或rgba() 语法可用于 0 至 255 之间的整数值或百分比值。hsv() ,hsva() hsl() 或hsla() 中的 s、v、l 和 a 的值范围都必须在 0-255 之间,或者使用百分比,h 的值范围必须在 0-359 之间。从 5.13.Examples 开始支持 HSL(A): /* opaque red */ QLabel { border-color: red } /* opaque red */ QLabel { border-color: #FF0000 } /* 75% opaque red */ QLabel { border-color: rgba(255, 0, 0, 75%) } /* opaque red */ QLabel { border-color: rgb(255, 0, 0) } /* opaque red */ QLabel { border-color: rgb(100%, 0%, 0%) } /* opaque yellow */ QLabel { border-color: hsv(60, 100%, 100%) } /* 75% blue */ QLabel { border-color: hsva(240, 255, 255, 75%) } /* opaque yellow */ QLabel { border-color: hsl(60, 100%, 50%) } /* 75% blue */ QLabel { border-color: hsla(240, 255, 50%, 75%) } 注意: 允许使用的 RGB 颜色与 CSS 2.1 允许使用的颜色相同,如此处所列。 |
字体 | (字体样式|字体重量){0,2}。字体大小字符串 | 速记字体属性。 |
字体大小 | 长度 | 字体的大小。 |
字体样式 | normal | italic | oblique | The style of a font. |
字体重量 | normal | bold | 100 | 200 ... | 900 | The weight of a font. |
渐变 | qlineargradient | qradialgradient | qconicalgradient | Specifies gradient fills. There are three types of gradient fills:
渐变是在 "对象边界模式 "中指定的。设想渲染渐变的方框左上角为 (0,0),右下角为 (1,1)。梯度参数指定为 0 到 1 之间的百分比,这些值将在运行时推断为实际的方框坐标。也可以指定边界框以外的值(例如 -0.6 或 1.8)。 警告: 止点必须以升序排序。 举例说明 /* linear gradient from white to green */ QTextEdit { background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 white, stop: 0.4 gray, stop:1 green) } /* linear gradient from white to green */ QTextEdit { background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 white, stop: 0.4 rgba(10, 20, 30, 40), stop:1 rgb(0, 200, 230, 200)) } /* conical gradient from white to green */ QTextEdit { background: qconicalgradient(cx:0.5, cy:0.5, angle:30, stop:0 white, stop:1 #00FF00) } /* radial gradient from white to green */ QTextEdit { background: qradialgradient(cx:0, cy:0, radius: 1, fx:0.5, fy:0.5, stop:0 white, stop:1 green) } |
图标 | (Url(disabled |active |normal |selected )?(on |off )?)* | url、QIcon::Mode 和QIcon::State 的列表。 举例说明: * { file-icon: url(file.png), url(file_selected.png) selected; } QMessageBox { dialogbuttonbox-buttons-have-icons: true; dialog-ok-icon: url(ok.svg); dialog-cancel-icon: url(cancel.png), url(grayed_cancel.png) disabled; } |
长度 | 数字(px |pt |em |ex )? | 一个数字,后面跟一个测量单位。CSS 标准建议用户代理必须忽略非法值的声明。在 Qt 中,必须指定测量单位。为了与 Qt 的早期版本兼容,在大多数情况下,不带测量单位的数字都被视为像素。支持的单位有
不过,Qt XML 只限于 |
数字 | 十进制整数或实数 | 例如0 ,18 ,+127 ,-255 ,12.34 ,-.5 ,0009 。 |
起源 | margin | border | padding | content | Indicates which of four rectangles to use.
另请参阅 "方框模型"。 |
PaletteRole | alternate-base | accent | base | bright-text | button | button-text | dark | highlight | highlighted-text | light | link | link-visited | mid | midlight | placeholder-text | shadow | text | tooltip-base | tooltip-text | window | window-text | 这些值与小部件QPalette 中的Color roles 相对应 。例如, QPushButton { color: palette(dark); } |
半径 | 长度{1, 2} | 一个或两个长度。如果只指定了一个长度,它将用作定义角的四分之一圆的半径。如果指定两个长度,第一个长度是四分之一椭圆的水平半径,第二个长度是垂直半径。 |
重复 | repeat-x | repeat-y | repeat | no-repeat | A value indicating the nature of repetition.
|
Url | url(filename) | filename 是本地磁盘上或使用Qt 资源系统存储的文件名。设置图像会隐式地设置元素的宽度和高度。 |
伪状态列表
支持以下伪状态:
伪状态 | 说明 |
---|---|
:active | 当窗口部件位于活动窗口中时,该状态将被设置。 |
:adjoins-item | 当QTreeView 的::分支与项目相邻时,此状态被设置。 |
:alternate | 当QAbstractItemView::alternatingRowColors() 设置为 true 时,QAbstractItemView 的每一个交替行轮绘制行都会设置此状态。 |
:bottom | 项目将被定位在底部。例如,一个QTabBar ,其标签页位于底部。 |
:checked | 项目被选中。例如,QAbstractButton 的checked 状态。 |
:closable | 项目可以关闭。例如,QDockWidget 的QDockWidget::DockWidgetClosable 功能已打开。 |
:closed | 项目处于关闭状态。例如, 中的非展开项。QTreeView |
:default | 项目为默认状态。例如,default QPushButton 或QMenu 中的默认操作。 |
:disabled | 项目为disabled 。 |
:editable | QComboBox 是可编辑的。 |
:edit-focus | 项目具有编辑焦点(请参阅QStyle::State_HasEditFocus )。此状态仅适用于 Qt Extended 应用程序。 |
:enabled | 项目是enabled 。 |
:exclusive | 该项目是独占项目组的一部分。例如,专属QActionGroup 中的菜单项。 |
:first | 该项目是第一个(在列表中)。例如,QTabBar 中的第一个选项卡。 |
:flat | 项目是扁平的。例如,flat QPushButton 。 |
:floatable | 项目可以浮动。例如,QDockWidget 已打开QDockWidget::DockWidgetFloatable 功能。 |
:focus | 项目有input focus 。 |
:has-children | 项目有子项目。例如,QTreeView 中的项目有子项目。 |
:has-siblings | 项目有同级项目。例如,QTreeView 中的一个项目有同级项目。 |
:horizontal | 项目具有水平方向 |
:hover | 鼠标悬停在项目上。 |
:indeterminate | 项目状态不确定。例如,QCheckBox 或QRadioButton 是partially checked 。 |
:last | 项目是最后一个(在列表中)。例如,QTabBar 中的最后一个选项卡。 |
:left | 项目位于左侧。例如,QTabBar 的标签页位于左侧。 |
:maximized | 项目已最大化。例如,最大化的QMdiSubWindow 。 |
:middle | 项目位于中间(列表中)。例如,一个标签页不在QTabBar 的开头或结尾。 |
:minimized | 项目被最小化。例如,最小化的QMdiSubWindow 。 |
:movable | 项目可以左右移动。例如,QDockWidget 已打开QDockWidget::DockWidgetMovable 功能。 |
:no-frame | 项目没有边框。例如,无框架的QSpinBox 或QLineEdit 。 |
:non-exclusive | 项目属于非排他性项目组。例如,非独占QActionGroup 中的菜单项。 |
:off | 对于可以切换的项目,这适用于处于 "关闭 "状态的项目。 |
:on | 对于可以切换的项目,这适用于处于 "打开 "状态的部件。 |
:only-one | 该项目是(列表中的)唯一项目。例如,QTabBar 中的唯一选项卡。 |
:open | 项目处于打开状态。例如,QTreeView 中的展开项目,或QComboBox 或QPushButton 中的打开菜单。 |
:next-selected | 下一个项目(列表中)被选中。例如,QTabBar 中的选定选项卡就在该项目的旁边。 |
:pressed | 正在使用鼠标按下该项目。 |
:previous-selected | 上一个项目(列表中)被选中。例如,QTabBar 中的一个选项卡紧挨着所选选项卡。 |
:read-only | 项目标记为只读或不可编辑。例如,只读的QLineEdit 或不可编辑的QComboBox 。 |
:right | 项目位于右侧。例如,QTabBar ,其选项卡位于右侧。 |
:selected | 项目被选中。例如,QTabBar 中的选定选项卡或QMenu 中的选定项。 |
:top | 项目位于顶部。例如,QTabBar ,其选项卡位于顶部。 |
:unchecked | 项目是unchecked 。 |
:vertical | 项目垂直放置。 |
:window | 部件是窗口(即顶层部件)。 |
子控件列表
以下是可用的子控件:
子控件 | 说明 |
---|---|
::add-line | 用于添加QScrollBar 行的按钮。 |
::add-page | QScrollBar 的手柄(滑块)和添加行之间的区域。 |
::branch | QTreeView 的分支指示器。 |
::chunk | QProgressBar 的进度块。 |
::close-button | QDockWidget 的关闭按钮或标签页。QTabBar |
::corner | 网页中两个滚动条之间的角落QAbstractScrollArea |
::down-arrow | QComboBox 、QHeaderView (排序指示符)、QScrollBar 或QSpinBox 的向下箭头。 |
::down-button | QScrollBar 或QSpinBox 的下拉按钮。 |
::drop-down | QComboBox 中的下拉按钮。 |
::float-button | 浮动按钮QDockWidget |
::groove | QSlider 的凹槽。 |
::indicator | QAbstractItemView 、QCheckBox 、QRadioButton 、可选中的QMenu 项或可选中的QGroupBox 的指示器。 |
::handle | QScrollBar 、QSplitter 或QSlider 的手柄(滑块)。 |
::icon | QAbstractItemView 或QMenu 的图标。 |
::item | QAbstractItemView 、QMenuBar 、QMenu 或QStatusBar 中的项目。 |
::left-arrow | QScrollBar 的左箭头。 |
::left-corner | QTabWidget 的左角。例如,该控件可用于控制QTabWidget 中左角部件的位置。 |
::menu-arrow | 带有菜单的QToolButton 的箭头。 |
::menu-button | QToolButton 的菜单按钮。 |
::menu-indicator | QPushButton 的菜单指示器。 |
::right-arrow | QMenu 或QScrollBar 的右箭头。 |
::pane | QTabWidget 的窗格(框架)。 |
::right-corner | QTabWidget 的右角。例如,该控件可用于控制QTabWidget 中右角部件的位置。 |
::scroller | QMenu 或QTabBar 的滚动器。 |
::section | QHeaderView 的部分。 |
::separator | QMenu 或QMainWindow 中的分隔符。 |
::sub-line | QScrollBar 中减去一行的按钮。 |
::sub-page | QScrollBar 的手柄(滑块)和子行之间的区域。 |
::tab | QTabBar 或QToolBox 的制表符。 |
::tab-bar | QTabWidget 的标签栏。该子控件仅用于控制QTabBar 在QTabWidget 内的位置。使用::tab子控件样式化标签。 |
::tear | QTabBar 的撕毁指示器。 |
::tearoff | QMenu 的撕离指示符。 |
::text | QAbstractItemView 的文本。 |
::title | QGroupBox 或QDockWidget 的标题。 |
::up-arrow | QHeaderView (排序指示符)、QScrollBar 或QSpinBox 的向上箭头。 |
::up-button | QSpinBox 的向上按钮。 |
有关如何自定义子控件的示例,请参阅自定义QPushButton 的菜单指示器子控件。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.