Qt 样式表参考

Qt 样式表支持各种特性、伪状态及子控件 (使定制 Widget 外观成为可能)。

可样式化 Widget 列表

下表列出可以使用样式表进行定制的 Qt Widgets:

Widget 如何样式化
QAbstractScrollArea 支持 Box 模型 .

所有衍生的 QAbstractScrollArea ,包括 QTextEdit ,和 QAbstractItemView (所有项视图类),支持可卷动背景使用 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 支持 Box 模型 。可以样式化复选指示器使用 ::indicator 子控件。默认情况下,指示器放在 Widget 内容矩形的左上角。

The spacing 特性指定复选指示器和文本之间的间距。

定制 QCheckBox 范例。
QColumnView The grip can be styled by using the image 特性。

The arrow indicators can by styled using the ::left-arrow 子控件和 ::right-arrow 子控件。
QComboBox The frame around the combobox can be styled using the Box 模型 .

The drop-down button can be styled using the ::drop-down subcontrol. By default, the drop-down button is placed in the top right corner of the padding rectangle of the widget.

The arrow mark inside the drop-down button can be styled using the ::down-arrow subcontrol. By default, the arrow is placed in the center of the contents rectangle of the drop-down subcontrol.

占位符文本的颜色的设置可用使用 placeholder-text-color 特性。

定制 QComboBox 范例。
QDateEdit QSpinBox .
QDateTimeEdit QSpinBox .
QDialog 仅支持 background , background-clip and background-origin 特性。

警告: 确保定义 Q_OBJECT 宏为自定义 Widget。

QDialogButtonBox The layout of buttons can be altered using the button-layout 特性。
QDockWidget Supports styling of the title bar and the title bar buttons when docked.

The dock widget border can be styled using the border property. The ::title subcontrol can be used to customize the title bar. The close and float buttons are positioned with respect to the ::title subcontrol using the ::close-button and ::float-button 分别。

When the title bar is vertical, the :vertical pseudo class is set. In addition, depending on QDockWidget::DockWidgetFeature :closable , :floatable and :movable pseudo states are set.

注意: 使用 QMainWindow::separator 以样式化重置手柄大小。

警告: 样式表不起作用当 QDockWidget is undocked as Qt uses native top level windows when undocked.

定制 QDockWidget 范例。

QDoubleSpinBox QSpinBox .
QFrame 支持 Box 模型 .

从 4.3 起,设置样式表在 QLabel 自动设置 QFrame::frameStyle 特性到 QFrame::StyledPanel .

定制 QFrame 范例。
QGroupBox 支持 Box 模型 .

The title can be styled using the ::title subcontrol. By default, the title is placed depending on QGroupBox::textAlignment.

In the case of a checkable QGroupBox , the title includes the check indicator. The indicator is styled using the ::indicator 子控件。 spacing property can be used to control the spacing between the text and indicator.

定制 QGroupBox 范例。
QHeaderView 支持 Box 模型 .

The sections of the header view are styled using the ::section 子控件。 section 子控件支持 :middle , :first , :last , :only-one , :next-selected , :previous-selected , :selected ,和 :checked 伪状态。

The sort indicator can be styled using the ::up-arrow ::down-arrow 子控件。

定制 QHeaderView 范例。
QLabel 支持 Box 模型 。不支持 :hover 伪状态。

从 4.3 起,设置样式表在 QLabel 自动设置 QFrame::frameStyle 特性到 QFrame::StyledPanel .

定制 QFrame 范例 ( QLabel 派生自 QFrame ).
QLineEdit 支持 Box 模型 .

样式化选中项的颜色和背景是使用 selection-color and selection-background-color 分别。

占位符文本的颜色的设置可用使用 placeholder-text-color 特性。

The password character can be styled using the lineedit-password-character 特性。

The password mask delay can be changed using the lineedit-password-mask-delay

定制 QLineEdit 范例。
QListView 支持 Box 模型 .

交替行颜色 被启用,样式化交替颜色可以使用 alternate-background-color 特性。

样式化选中项的颜色和背景是使用 selection-color and selection-background-color 分别。

选定行为的控制是通过 show-decoration-selected 特性。

使用 ::item subcontrol for more fine grained control over the items in the QListView .

QAbsractScrollArea 以样式化可卷动背景。

定制 QListView 范例。
QListWidget QListView .
QMainWindow Supports styling of the separator.

分隔符在 QMainWindow 当使用 QDockWidget 的样式化是使用 ::separator 子控件。

定制 QMainWindow 范例。
QMenu 支持 Box 模型 .

Individual items are styled using the ::item subcontrol. In addition to the usually supported pseudo states, item 子控件支持 :selected , :default , :exclusive non-exclusive 伪状态。

The indicator of checkable menu items is styled using the ::indicator 子控件。

The separator is styled using the ::separator 子控件。

For items with a sub menu, the arrow marks are styled using the right-arrow and left-arrow .

The scroller is styled using the ::scroller .

The tear-off is styled using the ::tearoff .

定制 QMenu 范例。
QMenuBar 支持 Box 模型 .

The spacing property specifies the spacing between menu items. Individual items are styled using the ::item 子控件。

警告: When running on Qt/Mac, the menu bar is usually embedded into the system-wide menu bar. In this case, the style sheet will have no effect.

定制 QMenuBar 范例。

QMessageBox The messagebox-text-interaction-flags property can be used to alter the interaction with text in the message box.
QProgressBar 支持 Box 模型 .

The chunks of the progress bar can be styled using the ::chunk subcontrol. The chunk is displayed on the Contents rectangle of the widget.

If the progress bar displays text, use the text-align property to position the text.

不确定的进度条拥有 :indeterminate 伪状态设置。

定制 QProgressBar 范例。
QPushButton 支持 Box 模型 .

支持 :default , :flat , :checked 伪状态。

从 5.15 起, icon 特性可以设置以覆写按钮图标。

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.

警告: If you only set a background-color on a QPushButton , the background may not appear unless you set the border property to some value. This is because, by default, the QPushButton draws a native border which completely overlaps the background-color. For example,

QPushButton { background-color: red; border: none; }
				

定制 QPushButton 范例。

QRadioButton 支持 Box 模型 .

复选指示器可以样式化使用 ::indicator 子控件。默认情况下,指示器放在 Widget 内容矩形的左上角。

The spacing 特性指定复选指示器和文本之间的间距。

定制 QRadioButton 范例。
QScrollBar 支持 Box 模型 .

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 :vertical 伪状态。

The slider can be styled using the ::handle subcontrol. Setting the min-width or min-height provides size constraints for the slider depending on the orientation.

The ::add-line subcontrol can be used to style the button to add a line. By default, the add-line subcontrol is placed in top right corner of the Border rectangle of the widget. Depending on the orientation the ::right-arrow or ::down-arrow . By default, the arrows are placed in the center of the Contents rectangle of the add-line subcontrol.

The ::sub-line subcontrol can be used to style the button to subtract a line. By default, the sub-line subcontrol is placed in bottom right corner of the Border rectangle of the widget. Depending on the orientation the ::left-arrow or ::up-arrow . By default, the arrows are placed in the center of the Contents rectangle of the sub-line subcontrol.

The ::sub-page subcontrol can be used to style the region of the slider that subtracts a page. The ::add-page subcontrol can be used to style the region of the slider that adds a page.

定制 QScrollBar 范例。
QSizeGrip 支持 width , height ,和 image 特性。

定制 QSizeGrip 范例。
QSlider 支持 Box 模型 .

For horizontal slides, the min-width and height 特性必须提供。对于垂直滑块, min-height and width 特性必须提供。

The groove of the slider is styled using the ::groove . The groove is positioned by default in the Contents rectangle of the widget. The thumb of the slider is styled using ::handle subcontrol. The subcontrol moves in the Contents rectangle of the groove subcontrol.

定制 QSlider 范例。
QSpinBox The frame of the spin box can be styled using the Box 模型 .

The up button and arrow can be styled using the ::up-button and ::up-arrow subcontrols. By default, the up-button is placed in the top right corner in the Padding rectangle of the widget. Without an explicit size, it occupies half the height of its reference rectangle. The up-arrow is placed in the center of the Contents rectangle of the up-button.

The down button and arrow can be styled using the ::down-button and ::down-arrow subcontrols. By default, the down-button is placed in the bottom right corner in the Padding rectangle of the widget. Without an explicit size, it occupies half the height of its reference rectangle. The bottom-arrow is placed in the center of the Contents rectangle of the bottom-button.

定制 QSpinBox 范例。
QSplitter 支持 Box 模型 。分割器手柄的样式化是使用 ::handle 子控件。

定制 QSplitter 范例。
QStatusBar 仅支持 background 特性。单个项框架的样式化可以使用 ::item 子控件。

定制 QStatusBar 范例。
QTabBar 单个选项卡的样式化可以使用 ::tab 子控件。关闭按钮使用 ::close-button . The tabs support the :only-one , :first , :last , :middle , :previous–selected , :next-selected , :selected 伪状态。

The :top , :left , :right , :bottom 伪状态从属选项卡取向。

selected 状态重叠选项卡的创建可以使用负边距或使用 absolute 位置方案。

撕裂指示器对于 QTabBar 的样式化是使用 ::tear 子控件。

QTabBar 使用两 QToolButton 的滚动器的样式化可以使用 QTabBar QToolButton 选择器。卷动按钮宽度的指定是使用 ::scroller 子控件。

选项卡的对齐方式在 QTabBar 的样式化是使用 alignment 特性。

警告: 要改变位置对于 QTabBar QTabWidget ,使用 tab-bar 子控件 (并设置 subcontrol-position)。

Customizing QTabBar 范例。

QTabWidget QTabWidget 框架的的样式化是使用 ::pane 子控件。左右角落的样式化是使用 ::left-corner and ::right-corner 分别。选项卡栏位置的控制是使用 ::tab-bar 子控件。

默认情况下,子控件拥有位置对于 QTabWidget 在 QWindowsStyle。要放置 QTabBar 在中心,设置选项卡栏子控件的 subcontrol-position。

The :top , :left , :right , :bottom 伪状态从属选项卡取向。

Customizing QTabWidget 范例。
QTableView 支持 Box 模型 。当 交替行颜色 被启用,样式化交替颜色可以使用 alternate-background-color 特性。

样式化选中项的颜色和背景是使用 selection-color and selection-background-color 分别。

角落 Widget 在 QTableView 的实现如 QAbstractButton 且样式化可以使用 QTableView QTableCornerButton::section 选择器。

警告: 若仅设置 QTableCornerButton 背景颜色,背景可能不出现,除非将 border (边框) 特性设为某值。这是因为,默认情况下,QTableCornerButton 会绘制完全重叠背景色的本机边框。

栅格颜色的指定可以使用 gridline-color 特性。

QAbsractScrollArea 以样式化可卷动背景。

定制 QTableView 范例。

QTableWidget QTableView .
QTextEdit 支持 Box 模型 .

选中文本的颜色和背景的样式化是使用 selection-color and selection-background-color 分别。

占位符文本的颜色的设置可用使用 placeholder-text-color 特性。

QAbsractScrollArea 以样式化可卷动背景。
QTimeEdit QSpinBox .
QToolBar 支持 Box 模型 .

The :top , :left , :right , :bottom pseudo states depending on the area in which the tool bar is grouped.

The :first , :last , :middle , :only-one pseudo states indicator the position of the tool bar within a line group (See QStyleOptionToolBar::positionWithinLine ).

分隔符对于 QToolBar 的样式化是使用 ::separator 子控件。

(移动工具栏的) 手柄的样式化是使用 ::handle 子控件。

定制 QToolBar 范例。
QToolButton 支持 Box 模型 .

QToolButton 拥有菜单,是 ::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.

QToolButton 是在 QToolButton::MenuButtonPopup 模式, ::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.

QToolButton 显示箭头, ::up-arrow , ::down-arrow , ::left-arrow and ::right-arrow subcontrols are used.

警告: If you only set a background-color on a QToolButton , the background will not appear unless you set the border property to some value. This is because, by default, the QToolButton draws a native border which completely overlaps the background-color. For example,

QToolButton { background-color: red; border: none; }
				

定制 QToolButton 范例。

QToolBox 支持 Box 模型 .

The individual tabs can by styled using the ::tab subcontrol. The tabs support the :only-one , :first , :last , :middle , :previous-selected , :next-selected , :selected 伪状态。
QToolTip 支持 Box 模型 opacity property controls the opacity of the tooltip.

定制 QFrame 范例 ( QToolTip QFrame ).
QTreeView 支持 Box 模型 。当 交替行颜色 被启用,样式化交替颜色可以使用 alternate-background-color 特性。

样式化选中项的颜色和背景是使用 selection-color and selection-background-color 分别。

选定行为的控制是通过 show-decoration-selected 特性。

The branches of the tree view can be styled using the ::branch subcontrol. The ::branch Sub-control supports the :open , :closed , :has-sibling and :has-children 伪状态。

使用 ::item subcontrol for more fine grained control over the items in the QTreeView .

QAbsractScrollArea 以样式化可卷动背景。

定制 QTreeView for an example to style the branches.
QTreeWidget QTreeView .
QWidget 仅支持 background , background-clip and background-origin 特性。

若子类来自 QWidget ,需要提供 paintEvent 为自定义 QWidget 如下:
void CustomWidget::paintEvent(QPaintEvent *)
{
    QStyleOption opt;
    opt.initFrom(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
				

以上代码无操作,若未设置样式表。

警告: 确保定义 Q_OBJECT 宏为自定义 Widget。

特性列表

This section lists all the properties supported by Qt Style Sheets. Which values can be given to a property depend on the 特性类型 . Unless otherwise specified, the following properties apply to all widgets. Properties marked with an asterisk * are specific to Qt and have no equivalent in CSS2 or CSS3. The Qt-specific properties are the following:

accent-color

类型 Brush

The property sets the Accent , which is used to emphasize interactive UI elements. If this property is not set, it defaults to the highlight 颜色。

alternate-background-color

类型 Brush

The 替代背景颜色 用于 QAbstractItemView 子类。

若此特性未设置,将默认值设为调色板的 AlternateBase 角色。

范例:

QTreeView {
    alternate-background-color: blue;
    background: yellow;
}
	

另请参阅 background and selection-background-color .

background

类型 Background

Shorthand notation for setting the background. Equivalent to specifying background-color , background-image , background-repeat , and/or background-position .

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QDialog , QFrame , QGroupBox , QLabel , QLineEdit , QMenu , QMenuBar , QPushButton , QRadioButton , QSplitter , QTextEdit , QToolTip ,和纯 QWidget

范例:

QTextEdit { background: yellow }
	

Often, it is required to set a fill pattern similar to the styles in Qt::BrushStyle . You can use the background-color property for Qt::SolidPattern , Qt::RadialGradientPattern , Qt::LinearGradientPattern and Qt::ConicalGradientPattern . The other patterns are easily achieved by creating a background image that contains the pattern.

范例:

QLabel {
    background-image: url(dense6pattern.png);
    background-repeat: repeat-xy;
}
	

另请参阅 background-origin , selection-background-color , background-clip , background-attachment and alternate-background-color .

background-color

类型 Brush

用于 Widget 的背景颜色。

范例:

QLabel { background-color: yellow }
QLineEdit { background-color: rgb(255, 0, 0) }
	

background-image

类型 Url

The background image used for the widget. Semi-transparent parts of the image let the background-color shine through.

范例:

QFrame { background-image: url(:/images/hydro.png) }
	

background-repeat

类型 Repeat

Whether and how the background image is repeated to fill the background-origin 矩形。

If this property is not specified, the background image is repeated in both directions ( repeat ).

范例:

QFrame {
    background: white url(:/images/ring.png);
    background-repeat: repeat-y;
    background-position: left;
}
	

background-position

类型 Alignment

背景图像的对齐方式在 background-origin 矩形。

若此特性未指定,对齐方式为 top left .

范例:

QFrame {
    background: url(:/images/footer.png);
    background-position: bottom left;
}
	

background-attachment

类型 Attachment

确定 background-image 是否在 QAbstractScrollArea is scrolled or fixed with respect to the viewport. By default, the background-image scrolls with the viewport.

范例:

QTextEdit {
    background-image: url("leaves.png");
    background-attachment: fixed;
}
	

另请参阅 background

background-clip

类型 Origin

Widget 的矩形,在那里 background 被绘制。

此特性指定矩形以在那里 background-color and 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 and Box 模型 .

background-origin

类型 Origin

Widget 的背景矩形,用于结合 background-position and background-image .

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QDialog , QFrame , QGroupBox , QLabel , QPushButton , QRadioButton , QSplitter , QTextEdit , QToolTip ,和纯 QWidget

如果此特性未指定,默认为 padding .

范例:

QFrame {
    background-image: url(:/images/header.png);
    background-position: top left;
    background-origin: content;
}
	

另请参阅 background and Box 模型 .

border

类型 Border

Shorthand notation for setting the widget's border. Equivalent to specifying border-color , border-style , and/or border-width .

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QFrame , QGroupBox , QLabel , QLineEdit , QMenu , QMenuBar , QPushButton , QRadioButton , QSplitter , QTextEdit , QToolTip ,和纯 QWidget

范例:

QLineEdit { border: 1px solid white }
	

border-top

类型 Border

Shorthand notation for setting the widget's top border. Equivalent to specifying border-top-color , border-top-style , and/or border-top-width .

border-right

类型 Border

Shorthand notation for setting the widget's right border. Equivalent to specifying border-right-color , border-right-style , and/or border-right-width .

border-bottom

类型 Border

Shorthand notation for setting the widget's bottom border. Equivalent to specifying border-bottom-color , border-bottom-style , and/or border-bottom-width .

border-left

类型 Border

Shorthand notation for setting the widget's left border. Equivalent to specifying border-left-color , border-left-style , and/or border-left-width .

border-color

类型 Box Colors

The color of all the border's edges. Equivalent to specifying 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 ,和纯 QWidget

若此特性未指定,默认为 color (i.e., the widget's foreground color).

范例:

QLineEdit {
    border-width: 1px;
    border-style: solid;
    border-color: white;
}
	

另请参阅 border-style , border-width , border-image ,和 Box 模型 .

border-top-color

类型 Brush

The color of the border's top edge.

border-right-color

类型 Brush

The color of the border's right edge.

border-bottom-color

类型 Brush

The color of the border's bottom edge.

border-left-color

类型 Brush

The color of the border's left edge.

border-image

类型 Border Image

The image used to fill the border. The image is cut into nine parts and stretched appropriately if necessary. See Border Image 了解细节。

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QFrame , QGroupBox , QLabel , QLineEdit , QMenu , QMenuBar , QPushButton , QRadioButton , QSplitter , QTextEdit and QToolTip .

另请参阅 border-color , border-style , border-width ,和 Box 模型 .

border-radius

类型 Radius

The radius of the border's corners. Equivalent to specifying border-top-left-radius , border-top-right-radius , border-bottom-right-radius ,和 border-bottom-left-radius .

The border-radius clips the element's background .

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QFrame , QGroupBox , QLabel , QLineEdit , QMenu , QMenuBar , QPushButton , QRadioButton , QSplitter , QTextEdit ,和 QToolTip .

If this property is not specified, it defaults to 0.

范例:

QLineEdit {
    border-width: 1px;
    border-style: solid;
    border-radius: 4px;
}
	

另请参阅 border-width and Box 模型 .

border-top-left-radius

类型 Radius

The radius of the border's top-left corner.

border-top-right-radius

类型 Radius

The radius of the border's top-right corner.

border-bottom-right-radius

类型 Radius

The radius of the border's bottom-right corner. Setting this property to a positive value results in a rounded corner.

border-bottom-left-radius

类型 Radius

The radius of the border's bottom-left corner. Setting this property to a positive value results in a rounded corner.

border-style

类型 Border Style

所有边框边缘的样式。

此特性的支持通过 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 ,和 Box 模型 .

border-top-style

类型 Border Style }

The style of the border's top edge.

border-right-style

类型 Border Style

The style of the border's right edge.

border-bottom-style

类型 Border Style

The style of the border's bottom edge.

border-left-style

类型 Border Style

The style of the border's left edge.

border-width

类型 Box Lengths

The width of the border. Equivalent to setting 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 ,和 Box 模型 .

border-top-width

类型 长度

The width of the border's top edge.

border-right-width

类型 长度

The width of the border's right edge.

border-bottom-width

类型 长度

The width of the border's bottom edge.

border-left-width

类型 长度

The width of the border's left edge.

bottom

类型 长度

position is relative (the default), moves a subcontrol by a certain offset up; specifying bottom: y is then equivalent to specifying top: -y .

position is absolute bottom property specifies the subcontrol's bottom edge in relation to the parent's bottom edge (see also subcontrol-origin ).

范例:

QSpinBox::down-button { bottom: 2px }
	

另请参阅 left , right ,和 top .

button-layout

类型 Number

The layout of buttons in a QDialogButtonBox QMessageBox . The possible values are 0 ( WinLayout ), 1 ( MacLayout ), 2 ( KdeLayout ), 3 ( GnomeLayout ) and 5 ( AndroidLayout ).

若此特性未指定,默认为当前样式指定值对于 SH_DialogButtonLayout 样式提示。

范例:

* { button-layout: 2 }
	

color

类型 Brush

颜色用于渲染文本。

This property is supported by all widgets that respect the QWidget::palette .

If this property is not set, the default is whatever is set for in the widget's palette for the QWidget::foregroundRole (typically black).

范例:

QPushButton { color: red }
	

另请参阅 background and selection-color .

dialogbuttonbox-buttons-have-icons

类型 布尔

Whether the buttons in a QDialogButtonBox show icons

If this property is set to 1, the buttons of a QDialogButtonBox show icons; if it is set to 0, the icons are not shown.

图标列表 section for information on how to set icons.

QDialogButtonBox { dialogbuttonbox-buttons-have-icons: 1; }
	

注意: Styles defining this property must be applied before the QDialogButtonBox is created; this means that you must apply the style to the parent widget or to the application itself.

font

类型 Font

Shorthand notation for setting the text's font. Equivalent to specifying font-family , font-size , font-style , and/or font-weight .

This property is supported by all widgets that respect the QWidget::font .

If this property is not set, the default is the 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

类型 字体粗细

字体的精细。

gridline-color*

类型 颜色

栅格线的颜色在 QTableView .

若此特性未指定,默认为当前样式指定值对于 SH_Table_GridLineColor 样式提示。

范例:

* { gridline-color: gray }
	

height

类型 长度

子控件 (或在某些情况下的 Widget) 的高度。

If this property is not specified, it defaults to a value that depends on the subcontrol/widget and on the current style.

警告: Unless otherwise specified, this property has no effect when set on widgets. If you want a widget with a fixed height, set the min-height and max-height to the same value.

范例:

QSpinBox::down-button { height: 10px }
	

另请参阅 width .

icon

类型 Url +

The icon that is used, for widgets that have an icon.

The only widget currently supporting this property is QPushButton .

注意: It's the application's responsibility to assign an icon to a button (using the QAbstractButton API), and not the style's. So be careful setting it unless your stylesheet is targeting a specific application.

从 5.15 起可用。

icon-size

类型 长度

Widget 图标的宽度和高度。

使用此特性,可以设置下列 Widget 的图标大小。

image*

类型 Url +

The image that is drawn in the contents rectangle of a subcontrol.

The image property accepts a list of Url s or an svg . The actual image that is drawn is determined using the same algorithm as QIcon (i.e) the image is never scaled up but always scaled down if necessary. If a svg is specified, the image is scaled to the size of the contents rectangle.

Setting the image property on sub controls implicitly sets the width and height of the sub-control (unless the image in a SVG).

In Qt 4.3 and later, the alignment of the image within the rectangle can be specified using image-position .

This property is for subcontrols only–we don't support it for other elements.

警告: The QIcon SVG plugin is needed to render SVG images.

范例:

// implicitly sets the size of down-button to the
// size of spindown.png
QSpinBox::down-button { image: url(:/images/spindown.png) }
	

image-position

类型 alignment

In Qt 4.3 and later, the alignment of the image image's position can be specified using relative or absolute position.

left

类型 长度

position is relative (the default), moves a subcontrol by a certain offset to the right.

position is absolute left property specifies the subcontrol's left edge in relation to the parent's left edge (see also subcontrol-origin ).

若此特性未指定,默认为 0 .

范例:

QSpinBox::down-button { left: 2px }
	

另请参阅 right , top ,和 bottom .

lineedit-password-character*

类型 Number

The QLineEdit password character as a Unicode number.

若此特性未指定,默认为当前样式指定值对于 SH_LineEdit_PasswordCharacter 样式提示。

范例:

* { lineedit-password-character: 9679 }
	

lineedit-password-mask-delay*

类型 Number

The QLineEdit password mask delay in milliseconds before lineedit-password-character is applied to visible character.

若此特性未指定,默认为当前样式指定值对于 SH_LineEdit_PasswordMaskDelay 样式提示。

Available since Qt 5.4.

范例:

* { lineedit-password-mask-delay: 1000 }
	

margin

类型 Box Lengths

The widget's margins. Equivalent to specifying 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 ,和 Box 模型 .

margin-top

类型 长度

Widget 上边距。

margin-right

类型 长度

Widget 右边距。

margin-bottom

类型 长度

Widget 下边距。

margin-left

类型 长度

Widget 左边距。

max-height

类型 长度

Widget 或子控件的最大高度。

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QFrame , QGroupBox , QLabel , QLineEdit , QMenu , QMenuBar , QPushButton , QRadioButton , QSizeGrip , QSpinBox , QSplitter , QStatusBar , QTextEdit ,和 QToolTip .

The value is relative to the contents rect in the Box 模型 .

范例:

QSpinBox { max-height: 24px }
	

另请参阅 max-width .

max-width

类型 长度

Widget 或子控件的最大宽度。

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QFrame , QGroupBox , QLabel , QLineEdit , QMenu , QMenuBar , QPushButton , QRadioButton , QSizeGrip , QSpinBox , QSplitter , QStatusBar , QTextEdit ,和 QToolTip .

The value is relative to the contents rect in the Box 模型 .

范例:

QComboBox { max-width: 72px }
	

另请参阅 max-height .

messagebox-text-interaction-flags*

类型 Number

The interaction behavior for text in a message box. Possible values are based on Qt::TextInteractionFlags .

若此特性未指定,默认为当前样式指定值对于 SH_MessageBox_TextInteractionFlags 样式提示。

范例:

QMessageBox { messagebox-text-interaction-flags: 5 }
	

min-height

类型 长度

Widget 或子控件的最小高度。

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QFrame , QGroupBox , QLabel , QLineEdit , QMenu , QMenuBar , QPushButton , QRadioButton , QSizeGrip , QSpinBox , QSplitter , QStatusBar , QTextEdit , QToolButton ,和 QToolTip .

If this property is not specified, the minimum height is derived based on the widget's contents and the style.

The value is relative to the contents rect in the Box 模型 .

范例:

QComboBox { min-height: 24px }
	

注意: Setting this property might allow widgets to shrink smaller than the space required for the contents.

另请参阅 min-width .

min-width

类型 长度

Widget 或子控件的最小宽度。

此特性的支持通过 QAbstractItemView 子类, QAbstractSpinBox 子类, QCheckBox , QComboBox , QFrame , QGroupBox , QLabel , QLineEdit , QMenu , QMenuBar , QPushButton , QRadioButton , QSizeGrip , QSpinBox , QSplitter , QStatusBar , QTextEdit , QToolButton ,和 QToolTip .

If this property is not specified, the minimum width is derived based on the widget's contents and the style.

The value is relative to the contents rect in the Box 模型 .

范例:

QComboBox { min-width: 72px }
	

注意: Setting this property might allow widgets to shrink smaller than the space required for the contents.

另请参阅 min-height .

opacity*

类型 Number

The opacity for a widget. Possible values are from 0 (transparent) to 255 (opaque). For the moment, this is only supported for tooltips .

若此特性未指定,默认为当前样式指定值对于 SH_ToolTipLabel_Opacity 样式提示。

范例:

QToolTip { opacity: 223 }
	

outline

围绕对象边框绘制的轮廓。

outline-color

类型 颜色

轮廓的颜色。另请参阅 border-color

outline-offset

类型 长度

从 Widget 边框起的轮廓偏移。

outline-style

指定用于绘制轮廓的模式。另请参阅 border-style

outline-radius

Adds rounded corners to the outline.

outline-bottom-left-radius

类型 Radius

The radius for the bottom-left rounded corner of the outline.

outline-bottom-right-radius

类型 Radius

The radius for the bottom-right rounded corner of the outline.

outline-top-left-radius

类型 Radius

The radius for the top-left corner of the outline.

outline-top-right-radius

类型 Radius

The radius for the top-right rounded corner of the outline.

padding

类型 Box Lengths

The widget's padding. Equivalent to specifying 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 ,和 Box 模型 .

padding-top

类型 长度

Widget 的顶部铺垫。

padding-right

类型 长度

Widget 的右侧铺垫。

padding-bottom

类型 长度

Widget 的底部铺垫。

padding-left

类型 长度

Widget 的左侧铺垫。

paint-alternating-row-colors-for-empty-area

类型 bool

是否 QTreeView 描绘用于空区域 (即:不存在项的区域) 的交替行颜色

placeholder-text-color*

类型 Brush

用于文本编辑 Widget 的占位符文本的颜色。

若此特性未设置,将默认值设为调色板的 PlaceholderText 角色。

范例:

QLineEdit { placeholder-text-color: #800000ff } /* semi-transparent blue */
	

从 6.5 起可用。

位置

类型 relative
| absolute

是否偏移指定使用 left , right , top ,和 bottom 是相对 (或绝对) 坐标。

若此特性未指定,默认为 relative .

类型 长度

position is relative (the default), moves a subcontrol by a certain offset to the left; specifying right: x is then equivalent to specifying left: -x .

position is absolute right property specifies the subcontrol's right edge in relation to the parent's right edge (see also subcontrol-origin ).

范例:

QSpinBox::down-button { right: 2px }
	

另请参阅 left , top ,和 bottom .

selection-background-color*

类型 Brush

选中文本 (或项) 的背景。

This property is supported by all widgets that respect the QWidget::palette and that show selection text.

若此特性未设置,将默认值设为调色板的 Highlight 角色。

范例:

QTextEdit { selection-background-color: darkblue }
	

另请参阅 selection-color and background .

selection-color*

类型 Brush

选中文本 (或项) 的前景。

This property is supported by all widgets that respect the QWidget::palette and that show selection text.

若此特性未设置,将默认值设为调色板的 HighlightedText 角色。

范例:

QTextEdit { selection-color: white }
	

另请参阅 selection-background-color and color .

show-decoration-selected*

类型 布尔

Controls whether selections in a QListView cover the entire row or just the extent of the text.

若此特性未指定,默认为当前样式指定值对于 SH_ItemView_ShowDecorationSelected 样式提示。

范例:

* { show-decoration-selected: 1 }
	

spacing*

类型 长度

Internal spacing in the widget.

此特性的支持通过 QCheckBox , checkable QGroupBox es, QMenuBar ,和 QRadioButton .

If this property is not specified, the default value depends on the widget and on the current style.

范例:

QMenuBar { spacing: 10 }
	

另请参阅 padding and margin .

subcontrol-origin*

类型 Origin

The origin rectangle of the subcontrol within the parent element.

如果此特性未指定,默认为 padding .

范例:

QSpinBox::up-button {
    image: url(:/images/spinup.png);
    subcontrol-origin: content;
    subcontrol-position: right top;
}
	

另请参阅 subcontrol-position .

subcontrol-position*

类型 Alignment

The alignment of the subcontrol within the origin rectangle specified by subcontrol-origin .

If this property is not specified, it defaults to a value that depends on the subcontrol.

范例:

QSpinBox::down-button {
    image: url(:/images/spindown.png);
    subcontrol-origin: padding;
    subcontrol-position: right bottom;
}
	

另请参阅 subcontrol-origin .

titlebar-show-tooltips-on-buttons

类型 bool

Whether tool tips are shown on window title bar buttons.

widget-animation-duration*

类型 Number

How much an animation should last (in milliseconds). A value equal to zero means that the animations will be disabled.

若此特性未指定,默认为当前样式指定值对于 SH_Widget_Animation_Duration 样式提示。

Available since Qt 5.10.

范例:

* { widget-animation-duration: 100 }
	

text-align

类型 Alignment

The alignment of text and icon within the contents of the widget.

If this value is not specified, it defaults to the value that depends on the native style.

范例:

QPushButton {
    text-align: left;
}
	

此特性目前仅支持通过 QPushButton and QProgressBar .

text-decoration

类型 none
underline
overline
line-through

Additional text effects.

top

类型 长度

position is relative (the default), moves a subcontrol by a certain offset down.

position is absolute top property specifies the subcontrol's top edge in relation to the parent's top edge (see also subcontrol-origin ).

若此特性未指定,默认为 0 .

范例:

QSpinBox::up-button { top: 2px }
	

另请参阅 left , right ,和 bottom .

width

类型 长度

The width of a subcontrol (or a widget in some cases).

If this property is not specified, it defaults to a value that depends on the subcontrol/widget and on the current style.

警告: Unless otherwise specified, this property has no effect when set on widgets. If you want a widget with a fixed width, set the min-width and max-width to the same value.

范例:

QSpinBox::up-button { width: 12px }
	

另请参阅 height .

-qt-background-role

类型 PaletteRole

The background-color for the subcontrol or widget based on the chosen role.

-qt-style-features

类型 list

The list of CSS properties that you want to apply Qt-specific styles on.

注意: The list can only include properties that are not pixmap-based.

图标列表

Icons used in Qt can be customized using the following properties. Each of the properties listed in this section have the type 图标 .

Note that for icons to appear in buttons in a QDialogButtonBox , you need to set the dialogbuttonbox-buttons-have-icons property to true. Also, to customize the size of the icons, use the icon-size property.

名称 QStyle::StandardPixmap
backward-icon QStyle::SP_ArrowBack
cd-icon QStyle::SP_DriveCDIcon
computer-icon QStyle::SP_ComputerIcon
desktop-icon QStyle::SP_DesktopIcon
dialog-apply-icon QStyle::SP_DialogApplyButton
dialog-cancel-icon QStyle::SP_DialogCancelButton
dialog-close-icon QStyle::SP_DialogCloseButton
dialog-discard-icon QStyle::SP_DialogDiscardButton
dialog-help-icon QStyle::SP_DialogHelpButton
dialog-no-icon QStyle::SP_DialogNoButton
dialog-ok-icon QStyle::SP_DialogOkButton
dialog-open-icon QStyle::SP_DialogOpenButton
dialog-reset-icon QStyle::SP_DialogResetButton
dialog-save-icon QStyle::SP_DialogSaveButton
dialog-yes-icon QStyle::SP_DialogYesButton
directory-closed-icon QStyle::SP_DirClosedIcon
directory-icon QStyle::SP_DirIcon
directory-link-icon QStyle::SP_DirLinkIcon
directory-open-icon QStyle::SP_DirOpenIcon
dockwidget-close-icon QStyle::SP_DockWidgetCloseButton
downarrow-icon QStyle::SP_ArrowDown
dvd-icon QStyle::SP_DriveDVDIcon
file-icon QStyle::SP_FileIcon
file-link-icon QStyle::SP_FileLinkIcon
filedialog-contentsview-icon QStyle::SP_FileDialogContentsView
filedialog-detailedview-icon QStyle::SP_FileDialogDetailedView
filedialog-end-icon QStyle::SP_FileDialogEnd
filedialog-infoview-icon QStyle::SP_FileDialogInfoView
filedialog-listview-icon QStyle::SP_FileDialogListView
filedialog-new-directory-icon QStyle::SP_FileDialogNewFolder
filedialog-parent-directory-icon QStyle::SP_FileDialogToParent
filedialog-start-icon QStyle::SP_FileDialogStart
floppy-icon QStyle::SP_DriveFDIcon
forward-icon QStyle::SP_ArrowForward
harddisk-icon QStyle::SP_DriveHDIcon
home-icon QStyle::SP_DirHomeIcon
lineedit-clear-button-icon QStyle::SP_LineEditClearButton
leftarrow-icon QStyle::SP_ArrowLeft
messagebox-critical-icon QStyle::SP_MessageBoxCritical
messagebox-information-icon QStyle::SP_MessageBoxInformation
messagebox-question-icon QStyle::SP_MessageBoxQuestion
messagebox-warning-icon QStyle::SP_MessageBoxWarning
network-icon QStyle::SP_DriveNetIcon
rightarrow-icon QStyle::SP_ArrowRight
titlebar-contexthelp-icon QStyle::SP_TitleBarContextHelpButton
titlebar-maximize-icon QStyle::SP_TitleBarMaxButton
titlebar-menu-icon QStyle::SP_TitleBarMenuButton
titlebar-minimize-icon QStyle::SP_TitleBarMinButton
titlebar-normal-icon QStyle::SP_TitleBarNormalButton
titlebar-shade-icon QStyle::SP_TitleBarShadeButton
titlebar-unshade-icon QStyle::SP_TitleBarUnshadeButton
trash-icon QStyle::SP_TrashIcon
uparrow-icon QStyle::SP_ArrowUp

特性类型列表

下表汇总了不同特性类型的句法和含义。

类型 句法 描述
Alignment { top
| bottom
| left
| right
| center }*

水平和/或垂直对齐。

范例:

QTextEdit { background-position: bottom center }
				
Attachment { scroll
| fixed }*
卷动或固定附件。
Background { Brush
| Url
| Repeat
| Alignment }*
A sequence of Brush , Url , Repeat ,和 Alignment .
布尔 0 | 1 True ( 1 ) or false ( 0 ).

范例:

QDialog { etch-disabled-text: 1 }
			
Border { Border Style
| 长度
| Brush }*
Shorthand border property.
Border Image 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.

CSS3 Draft Specification 了解细节。

Border Style 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 了解细节。
Box Colors Brush {1,4} One to four occurrences of Brush , specifying the top, right, bottom, and left edges of a box, respectively. If the left color is not specified, it is taken to be the same as the right color. If the bottom color is not specified, it is taken to be the same as the top color. If the right color is not specified, it is taken to be the same as the top color.

范例:

/* red red red red */
QLabel { border-color: red }
/* red blue red blue */
QLabel { border-color: red blue }
/* red blue green blue */
QLabel { border-color: red blue green }
/* red blue green yellow */
QLabel { border-color: red blue green yellow }
		
Box Lengths 长度 {1,4} One to four occurrences of 长度 , specifying the top, right, bottom, and left edges of a box, respectively. If the left length is not specified, it is taken to be the same as the right length. If the bottom length is not specified, is it taken to be the same as the top length. If the right length is not specified, it is taken to be the same as the top length.

范例:

/* 1px 1px 1px 1px */
QLabel { border-width: 1px }
/* 1px 2px 1px 2px */
QLabel { border-width: 1px 2px }
/* 1px 2px 3px 2px */
QLabel { border-width: 1px 2px 3px }
/* 1px 2px 3px 4px */
QLabel { border-width: 1px 2px 3px 4px }
	
Brush 颜色
| Gradient
| PaletteRole
Specifies a Color or a Gradient or an entry in the Palette.
颜色 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
Specifies a color as RGB (red, green, blue), RGBA (red, green, blue, alpha), HSV (hue, saturation, value), HSVA (hue, saturation, value, alpha), HSL (hue, saturation, lightness), HSLA (hue, saturation, lightness, alpha) or a named color. The rgb() or rgba() syntax can be used with integer values between 0 and 255, or with percentages. The value of s, v, l and a in hsv() , hsva() hsl() or hsla() must all be in the range 0-255 or with percentages, the value of h must be in the range 0-359. The support for HSL(A) is available since 5.13.

范例:

/* 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%) }

注意: The RGB colors allowed are the same as those allowed with CSS 2.1, as listed here .

Font ( 字体样式 | 字体粗细 ){0,2} 字体大小 字符串 Shorthand font property.
字体大小 长度 字体大小。
字体样式 normal
| italic
| oblique
字体样式。
字体粗细 normal
| bold
| 100
| 200
...
| 900
字体的粗细。
Gradient qlineargradient
| qradialgradient
| qconicalgradient
Specifies gradient fills. There are three types of gradient fills:
  • Linear gradients interpolate colors between start and end points.
  • Radial gradients interpolate colors between a focal point and end points on a circle surrounding it.
  • Conical gradients interpolate colors around a center point.

Gradients are specified in Object Bounding Mode. Imagine the box in which the gradient is rendered, to have its top left corner at (0, 0) and its bottom right corner at (1, 1). Gradient parameters are then specified as percentages from 0 to 1. These values are extrapolated to actual box coordinates at runtime. It is possible specify values that lie outside the bounding box (-0.6 or 1.8, for instance).

警告: The stops have to appear sorted in ascending order.

范例:

/* 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 ( 被禁用 | active | normal | selected )? ( on | off )? )* A list of url, QIcon::Mode and 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;
}
长度 Number ( px | pt | em | ex )? A number followed by a measurement unit. The CSS standard recommends that user agents must ignore a declaration with an illegal value. In Qt, it is mandatory to specify measurement units. For compatibility with earlier versions of Qt, numbers without measurement units are treated as pixels in most contexts. The supported units are:
  • px : pixels
  • pt : the size of one point (i.e., 1/72 of an inch)
  • em : the size relative to the font size of the element (e.g., 2em means 2 times the size of the font)
  • ex : the x-height of the font (i.e., the height of 'x')

However, Qt is limited to font sizes in pt and px and any other size must be in px , em or ex .

Number A decimal integer or a real number 范例: 0 , 18 , +127 , -255 , 12.34 , -.5 , 0009 .
Origin margin
| border
| padding
| content
Indicates which of four rectangles to use.
  • margin : The margin rectangle. The margin falls outside the border.
  • border : The border rectangle. This is where any border is drawn.
  • padding : The padding rectangle. Unlike the margins, padding is located inside the border.
  • content : The content rectangle. This specifies where the actual contents go, excluding any padding, border, or margin.

另请参阅 Box 模型 .

PaletteRole alternate-base
| accent
| base
| bright-text
| button
| button-text
| dark
| highlight
| highlighted-text
| light
| link
| link-visited
| mid
| midlight
| shadow
| text
| window
| window-text
These values correspond the Color roles in the widget's QPalette .

例如,

QPushButton { color: palette(dark); }
Radius 长度 {1, 2} One or two occurrences of 长度 . If only one length is specified, it is used as the radius of the quarter circle defining the corner. If two lengths are specified, the first length is the horizontal radius of a quarter ellipse, whereas the second length is the vertical radius.
Repeat repeat-x
| repeat-y
| repeat
| no-repeat
A value indicating the nature of repetition.
  • repeat-x : Repeat horizontally.
  • repeat-y : Repeat vertically.
  • repeat : Repeat horizontally and vertically.
  • no-repeat : Don't repeat.
Url url(filename) filename is the name of a file on the local disk or stored using Qt 资源系统 . Setting an image implicitly sets the width and height of the element.

伪状态列表

支持下列伪状态:

伪状态 描述
:active 此状态被设置,当 Widget 在活动窗口中时。
:adjoins-item This state is set when the ::branch QTreeView is adjacent to an item.
:alternate This state is set for every alternate row whe painting the row of a QAbstractItemView QAbstractItemView::alternatingRowColors () is set to true.
:bottom The item is positioned at the bottom. For example, a QTabBar that has its tabs positioned at the bottom.
:checked The item is checked. For example, the checked state of QAbstractButton .
:closable The items can be closed. For example, the QDockWidget 拥有 QDockWidget::DockWidgetClosable feature turned on.
:closed The item is in the closed state. For example, an non-expanded item in a QTreeView
:default The item is the default. For example, a default QPushButton or a default action in a QMenu .
:disabled 项是 被禁用 .
:editable The QComboBox 是可编辑的。
:edit-focus The item has edit focus (See QStyle::State_HasEditFocus ). This state is available only for Qt Extended applications.
:enabled 项是 enabled .
:exclusive The item is part of an exclusive item group. For example, a menu item in a exclusive QActionGroup .
:first The item is the first (in a list). For example, the first tab in a QTabBar .
:flat 项是扁平的。例如, flat QPushButton .
:floatable The items can be floated. For example, the QDockWidget 拥有 QDockWidget::DockWidgetFloatable feature turned on.
:focus 项有 输入聚焦 .
:has-children The item has children. For example, an item in a QTreeView that has child items.
:has-siblings The item has siblings. For example, an item in a QTreeView that siblings.
:horizontal The item has horizontal orientation
:hover The mouse is hovering over the item.
:indeterminate The item has indeterminate state. For example, a QCheckBox or QRadioButton is partially checked .
:last The item is the last (in a list). For example, the last tab in a QTabBar .
:left The item is positioned at the left. For example, a QTabBar that has its tabs positioned at the left.
:maximized The item is maximized. For example, a maximized QMdiSubWindow .
:middle The item is in the middle (in a list). For example, a tab that is not in the beginning or the end in a QTabBar .
:minimized The item is minimized. For example, a minimized QMdiSubWindow .
:movable The item can be moved around. For example, the QDockWidget 拥有 QDockWidget::DockWidgetMovable feature turned on.
:no-frame The item has no frame. For example, a frameless QSpinBox or QLineEdit .
:non-exclusive The item is part of a non-exclusive item group. For example, a menu item in a non-exclusive QActionGroup .
:off For items that can be toggled, this applies to items in the "off" state.
:on For items that can be toggled, this applies to widgets in the "on" state.
:only-one The item is the only one (in a list). For example, a lone tab in a QTabBar .
:open The item is in the open state. For example, an expanded item in a QTreeView ,或 QComboBox or QPushButton with an open menu.
:next-selected The next item (in a list) is selected. For example, the selected tab of a QTabBar is next to this item.
:pressed The item is being pressed using the mouse.
:previous-selected The previous item (in a list) is selected. For example, a tab in a QTabBar that is next to the selected tab.
:read-only The item is marked read only or non-editable. For example, a read only QLineEdit or a non-editable QComboBox .
:right The item is positioned at the right. For example, a QTabBar that has its tabs positioned at the right.
:selected The item is selected. For example, the selected tab in a QTabBar or the selected item in a QMenu .
:top The item is positioned at the top. For example, a QTabBar that has its tabs positioned at the top.
:unchecked 项是 unchecked .
:vertical 项有垂直取向。
:window The widget is a window (i.e top level widget)

子控件列表

下列子控件可用:

Sub-Control 描述
::add-line The button to add a line of a QScrollBar .
::add-page The region between the handle (slider) and the add-line QScrollBar .
::branch The branch indicator of a QTreeView .
::chunk The progress chunk of a QProgressBar .
::close-button The close button of a QDockWidget or tabs of QTabBar
::corner The corner between two scrollbars in a QAbstractScrollArea
::down-arrow The down arrow of a QComboBox , QHeaderView (sort indicator), QScrollBar or QSpinBox .
::down-button The down button of a QScrollBar QSpinBox .
::drop-down The drop-down button of a QComboBox .
::float-button 浮动按钮对于 QDockWidget
::groove 凹槽对于 QSlider .
::indicator 指示器对于 QAbstractItemView QCheckBox QRadioButton ,可复选 QMenu item or a checkable QGroupBox .
::handle The handle (slider) of a QScrollBar QSplitter ,或 QSlider .
::icon The icon of a QAbstractItemView QMenu .
::item 项对于 QAbstractItemView QMenuBar QMenu ,或 QStatusBar .
::left-arrow The left arrow of a QScrollBar .
::left-corner The left corner of a QTabWidget . For example, this control can be used to control position the left corner widget in a QTabWidget .
::menu-arrow The arrow of a QToolButton with a menu.
::menu-button The menu button of a QToolButton .
::menu-indicator The menu indicator of a QPushButton .
::right-arrow The right arrow of a QMenu QScrollBar .
::pane 窗格 (框架) 对于 QTabWidget .
::right-corner The right corner of a QTabWidget . For example, this control can be used to control the position the right corner widget in a QTabWidget .
::scroller The scroller of a QMenu or QTabBar .
::section The section of a QHeaderView .
::separator 分隔符对于 QMenu 或在 QMainWindow .
::sub-line The button to subtract a line of a QScrollBar .
::sub-page The region between the handle (slider) and the sub-line QScrollBar .
::tab 选项卡对于 QTabBar or QToolBox .
::tab-bar 选项卡栏对于 QTabWidget 。此子控件的存在仅用于控制位置对于 QTabBar QTabWidget 。要样式选项卡使用 ::tab 子控件。
::tear 撕裂指示器对于 QTabBar .
::tearoff The tear-off indicator of a QMenu .
::text The text of a QAbstractItemView .
::title The title of a QGroupBox QDockWidget .
::up-arrow The up arrow of a QHeaderView (sort indicator), QScrollBar QSpinBox .
::up-button The up button of a QSpinBox .

定制 QPushButton 的菜单指示器子控件 有关如何定制子控件的范例。

使用样式表定制 Qt Widgets Qt 样式表范例

内容