ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Qt样式表参考:Qt Style Sheets

2021-06-19 21:58:42  阅读:428  来源: 互联网

标签:控件 Style Qt color 样式表 background subcontrol property border


Qt样式表支持各种属性、伪状态和子控件,使得定制小部件的外观成为可能。

 

可设置样式的小部件列表

下表列出了可以使用样式表自定义的Qt小部件:

Widget如何设计风格
QAbstractScrollArea

Supports the box model.

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.

See Customizing QAbstractScrollArea for an example.

支持盒子模型。 QAbstractScrollArea 的所有派生类,包括 QTextEdit 和 QAbstractItemView(所有项目视图类),都支持使用background-attachment的可滚动背景。 将 background-attachment 设置为 fixed 会提供不随视口滚动的background-image。 设置background-attachment滚动【scroll】,当滚动条移动时滚动背景图像。 有关示例,请参阅自定义 QAbstractScrollArea。

 

QCheckBoxSupports the box model. The check indicator can be styled using the ::indicator subcontrol. By default, the indicator is placed in the Top Left corner of the Contents rectangle of the widget.

The spacing property specifies the spacing between the check indicator and the text.

See Customizing QCheckBox for an example.

支持盒子模型。 可以使用 ::indicator 子控件设置检查指示器的样式。 默认情况下,指示器放置在小部件内容矩形的左上角。 间距属性指定检查指示符和文本之间的间距。 有关示例,请参阅自定义 QCheckBox。

QColumnView

The grip can be styled be using the image property. The arrow indicators can by styled using the ::left-arrow subcontrol and the ::right-arrow subcontrol.

可以使用图像属性来设置手柄的样式。 箭头指示符可以使用 ::left-arrow 子控件和 ::right-arrow 子控件来设置样式。

QComboBoxThe frame around the combobox can be styled using the box model. 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.

See Customizing QComboBox for an example.

组合框周围的框架可以使用框模型进行样式设置。 下拉按钮可以使用 ::drop-down 子控件设置样式。 默认情况下,下拉按钮位于小部件填充矩形的右上角。 下拉按钮内的箭头标记可以使用 ::down-arrow 子控件设置样式。 默认情况下,箭头位于下拉子控件的内容矩形的中心。 有关示例,请参阅自定义 QComboBox。

QDateEditSee QSpinBox.
QDateTimeEditSee QSpinBox.
QDialogSupports only the backgroundbackground-clip and background-origin properties.

Warning: Make sure you define the Q_OBJECT macro for your custom widget.

仅支持背景、背景剪辑和背景原点属性。 警告:确保为自定义小部件定义 Q_OBJECT 宏。

QDialogButtonBox

The layout of buttons can be altered using the button-layout property.

可以使用 button-layout 属性更改按钮的布局。

QDockWidgetSupports 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 respectively.

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

Note: Use QMainWindow::separator to style the resize handle.

Warning: The style sheet has no effect when the QDockWidget is undocked as Qt uses native top level windows when undocked.

See Customizing QDockWidget for an example.

 

停靠时支持标题栏和标题栏按钮的样式。 可以使用 border 属性设置停靠窗口小部件边框的样式。 ::title 子控件可用于自定义标题栏。 关闭和浮动按钮分别使用 ::close-button 和 ::float-button 相对于 ::title 子控件定位。 当标题栏是垂直的时,设置了 :vertical 伪类。 此外,根据 QDockWidget::DockWidgetFeature,设置 :closeable、:floatable 和 :movable 伪状态。 注意:使用 QMainWindow::separator 设置调整大小手柄的样式。 警告:当 QDockWidget 取消停靠时,样式表不起作用,因为 Qt 在取消停靠时使用本机顶级窗口。 有关示例,请参阅自定义 QDockWidget。

QDoubleSpinBoxSee QSpinBox.
QFrameSupports the box model.

Since 4.3, setting a stylesheet on a QLabel automatically sets the QFrame::frameStyle property to QFrame::StyledPanel.

See Customizing QFrame for an example.

支持盒子模型。 从 4.3 开始,在 QLabel 上设置样式表会自动将 QFrame::frameStyle 属性设置为 QFrame::StyledPanel。 有关示例,请参阅自定义 QFrame。

QGroupBoxSupports the box model. 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 subcontrol. The spacing property can be used to control the spacing between the text and indicator.

See Customizing QGroupBox for an example.

支持盒子模型。 可以使用 ::title 子控件设置标题的样式。 默认情况下,标题根据 QGroupBox::textAlignment 放置。 对于可检查的 QGroupBox,标题包含检查指示符。 指示器的样式使用 ::indicator 子控件。 间距属性可用于控制文本和指示器之间的间距。 有关示例,请参阅自定义 QGroupBox。

QHeaderViewSupports the box model. The sections of the header view are styled using the ::section sub control. The section Sub-control supports the :middle:first:last:only-one:next-selected:previous-selected:selected, and :checked pseudo states.

The sort indicator can be styled using the ::up-arrow and the ::down-arrow Sub-control.

See Customizing QHeaderView for an example.

支持盒子模型。 标题视图的部分使用 ::section 子控件设置样式。 子控件部分支持:middle、:first、:last、:only-one、:next-selected、:previous-selected、:selected 和 :checked 伪状态。 可以使用 ::up-arrow 和 ::down-arrow 子控件来设置排序指示器的样式。 有关示例,请参阅自定义 QHeaderView。

QLabelSupports the box model. Does not support the :hover pseudo-state.

Since 4.3, setting a stylesheet on a QLabel automatically sets the QFrame::frameStyle property to QFrame::StyledPanel.

See Customizing QFrame for an example (a QLabel derives from QFrame).

支持盒子模型。 不支持 :hover 伪状态。 从 4.3 开始,在 QLabel 上设置样式表会自动将 QFrame::frameStyle 属性设置为 QFrame::StyledPanel。 有关示例,请参阅自定义 QFrame(QLabel 派生自 QFrame)。

QLineEditSupport the box model.

The color and background of the selected item is styled using selection-color and selection-background-color respectively.

The password character can be styled using the lineedit-password-character property.

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

See Customizing QLineEdit for an example.

支持盒子模型。 所选项目的颜色和背景分别使用 selection-color 和 selection-background-color 设置样式。 可以使用 lineedit-password-character 属性设置密码字符的样式。 可以使用 lineedit-password-mask-delay 更改密码掩码延迟 有关示例,请参阅自定义 QLineEdit。

QListViewSupports the box model. When alternating row colors is enabled, the alternating colors can be styled using the alternate-background-color property.

The color and background of the selected item is styled using selection-color and selection-background-color respectively.

The selection behavior is controlled by the show-decoration-selected property.

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

See QAbsractScrollArea to style scrollable backgrounds.

See Customzing QListView for an example.

支持盒子模型。 启用交替行颜色后,可以使用交替背景颜色属性设置交替颜色的样式。 所选项目的颜色和背景分别使用 selection-color 和 selection-background-color 设置样式。 选择行为由 show-decoration-selected 属性控制。 使用 ::item 子控件对 QListView 中的项目进行更细粒度的控制。 请参阅 QAbsractScrollArea 以设置可滚动背景的样式。 有关示例,请参阅自定义 QListView。

QListWidgetSee QListView.
QMainWindowSupports styling of the separator

The separator in a QMainWindow when using QDockWidget is styled using the ::separator subcontrol.

See Customizing QMainWindow for an example.

支持分隔符的样式 使用 QDockWidget 时 QMainWindow 中的分隔符使用 ::separator 子控件进行样式设置。 有关示例,请参阅自定义 QMainWindow。

QMenuSupports the box model.

Individual items are styled using the ::item subcontrol. In addition to the usually supported pseudo states, item subcontrol supports the :selected:default:exclusive and the non-exclusive pseudo states.

The indicator of checkable menu items is styled using the ::indicator subcontrol.

The separator is styled using the ::separator subcontrol.

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.

See Customizing QMenu for an example.

支持盒子模型。 单个项目使用 ::item 子控件设置样式。 除了通常支持的伪状态外,项目子控件还支持 :selected、:default、:exclusive 和 non-exclusive 伪状态。 可检查菜单项的指示器使用 ::indicator 子控件设置样式。 分隔符使用 ::separator 子控件设置样式。 对于带有子菜单的项目,箭头标记的样式使用向右箭头和向左箭头。 滚动条使用 ::scroller 设置样式。 撕下的样式使用 ::tearoff。 有关示例,请参阅自定义 QMenu。

QMenuBarSupports the box model. The spacing property specifies the spacing between menu items. Individual items are styled using the ::item subcontrol.

Warning: 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.

See Customizing QMenuBar for an example.

支持盒子模型。 间距属性指定菜单项之间的间距。 单个项目使用 ::item 子控件设置样式。 警告:在 Qt/Mac 上运行时,菜单栏通常嵌入到系统范围的菜单栏中。 在这种情况下,样式表将不起作用。 有关示例,请参阅自定义 QMenuBar。

QMessageBox

The messagebox-text-interaction-flags property can be used to alter the interaction with text in the message box.

messagebox-text-interaction-flags 属性可用于更改与消息框中文本的交互。

QProgressBarSupports the box model. 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 progress bars have the :indeterminate pseudo state set.

See Customizing QProgressBar for an example.

支持盒子模型。 进度条的块可以使用 ::chunk 子控件设置样式。 该块显示在小部件的内容矩形上。 如果进度条显示文本,请使用 text-align 属性来定位文本。 不确定进度条设置了 :indeterminate 伪状态。 有关示例,请参阅自定义 QProgressBar。

QPushButtonSupports the box model. Supports the :default:flat:checked pseudo states.

Since 5.15, the icon property can be set to override the button 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.

Warning: 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; }

See Customizing QPushButton for an example.

支持盒子模型。 支持:default、:flat、:checked 伪状态。 从 5.15 开始,图标属性可以设置为覆盖按钮图标。 对于带有菜单的 QPushButton,菜单指示器的样式使用 ::menu-indicator 子控件。 可以使用 :open 和 :closed 伪状态自定义可检查按钮的外观。 警告:如果您只在 QPushButton 上设置背景颜色,除非您将边框属性设置为某个值,否则背景可能不会出现。 这是因为默认情况下,QPushButton 会绘制一个与背景颜色完全重叠的原生边框。 例如, QPushButton { background-color: red; border: none; }有关示例,请参阅自定义 QPushButton。

QRadioButtonSupports the box model. The check indicator can be styled using the ::indicator subcontrol. By default, the indicator is placed in the Top Left corner of the Contents rectangle of the widget.

The spacing property specifies the spacing between the check indicator and the text.

See Customizing QRadioButton for an example.

支持盒子模型。 可以使用 ::indicator 子控件设置检查指示器的样式。 默认情况下,指示器放置在小部件内容矩形的左上角。 间距属性指定检查指示符和文本之间的间距。 有关示例,请参阅自定义 QRadioButton。

QScrollBarSupports the box model. 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.

The slider can be styled using the ::handle subcontrol. Setting the min-width or min-height provides size contraints 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.

See Customizing QScrollBar for an example.

支持盒子模型。小部件的内容矩形被认为是滑块移动的凹槽。 QScrollBar 的范围(即宽度或高度取决于方向)分别使用 width 或 height 属性设置。要确定方向,请使用 :horizo​​ntal 和 :vertical 伪状态。 滑块可以使用 ::handle 子控件设置样式。设置 min-width 或 min-height 会根据方向为滑块提供尺寸限制。 ::add-line 子控件可用于设置按钮样式以添加一行。默认情况下,添加行子控件位于小部件边框矩形的右上角。根据方向,::right-arrow 或 ::down-arrow。默认情况下,箭头位于添加行子控件的内容矩形的中心。 ::sub-line 子控件可用于设置按钮样式以减去一行。默认情况下,子行子控件放置在小部件的边框矩形的右下角。根据方向,::left-arrow 或 ::up-arrow。默认情况下,箭头放置在子行子控件的内容矩形的中心。 ::sub-page 子控件可用于设置减去页面的滑块区域的样式。 ::add-page 子控件可用于设置添加页面的滑块区域的样式。 有关示例,请参阅自定义 QScrollBar。

QSizeGripSupports the widthheight, and image properties.

See Customizing QSizeGrip for an example.

支持宽度、高度和图像属性。 有关示例,请参阅自定义 QSizeGrip。

QSliderSupports the box model. For horizontal slides, the min-width and height properties must be provided. For vertical sliders, the min-height and width properties must be provided.

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.

See Customizing QSlider for an example.

支持盒子模型。 对于水平幻灯片,必须提供 min-width 和 height 属性。 对于垂直滑块,必须提供 min-height 和 width 属性。 滑块的凹槽使用 ::groove 设计。 默认情况下,凹槽位于小部件的内容矩形中。 滑块的拇指使用 ::handle 子控件设置样式。 子控件在凹槽子控件的内容矩形中移动。 有关示例,请参阅自定义 QSlider。

QSpinBoxThe frame of the spin box can be styled using the box model.

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.

See Customizing QSpinBox for an example.

旋转框的框架可以使用框模型进行样式设置。 可以使用 ::up-button 和 ::up-arrow 子控件设置向上按钮和箭头的样式。 默认情况下,向上按钮位于小部件的 Padding 矩形的右上角。 没有明确的大小,它占据其参考矩形高度的一半。 向上箭头位于向上按钮的内容矩形的中心。 可以使用 ::down-button 和 ::down-arrow 子控件设置向下按钮和箭头的样式。 默认情况下,向下按钮位于小部件的 Padding 矩形的右下角。 没有明确的大小,它占据其参考矩形高度的一半。 底部箭头位于底部按钮的内容矩形的中心。 有关示例,请参阅自定义 QSpinBox。

QSplitterSupports the box model. The handle of the splitter is styled using the ::handle subcontrol.

See Customizing QSplitter for an example.

支持盒子模型。 拆分器的句柄使用 ::handle 子控件进行样式设置。 有关示例,请参阅自定义 QSplitter。

QStatusBarSupports only the background property. The frame for individual items can be style using the ::item subcontrol.

See Customizing QStatusBar for an example.

仅支持背景属性。 单个项目的框架可以使用 ::item 子控件进行样式设置。 有关示例,请参阅自定义 QStatusBar。

QTabBarIndividual tabs may be styled using the ::tab subcontrol. Close buttons using the ::close-button The tabs support the :only-one:first:last:middle:previous--selected:next-selected:selected pseudo states.

The :top:left:right:bottom pseudo states depending on the orientation of the tabs.

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.

Warning:

To change the position of the QTabBar within a QTabWidget, use the tab-bar subcontrol (and set subcontrol-position).

See Customizing QTabBar for an example.

可以使用 ::tab 子控件设置单个选项卡的样式。 使用 ::close-button 的关闭按钮选项卡支持 :only-one, :first, :last, :middle, :previous--selected, :next-selected, :selected 伪状态。 :top, :left, :right, :bottom 伪状态取决于选项卡的方向。 所选状态的重叠标签是通过使用负边距或使用绝对位置方案创建的。 QTabBar 的撕裂指示器使用 ::tear 子控件设置样式。 QTabBar 为其滚动条使用了两个 QToolButton,可以使用 QTabBar QToolButton 选择器设置样式。 要指定滚动按钮的宽度,请使用 ::scroller 子控件。 QTabBar 中选项卡的对齐方式使用 alignment 属性设置样式。 警告: 要更改 QTabBar 在 QTabWidget 中的位置,请使用标签栏子控件(并设置子控件位置)。 有关示例,请参阅自定义 QTabBar。

QTabWidgetThe frame of the tab widget is styled using the ::pane subcontrol. The left and right corners are styled using the ::left-corner and ::right-corner respectively. The position of the tab bar is controlled using the ::tab-bar subcontrol.

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.

The :top:left:right:bottom pseudo states depending on the orientation of the tabs.

See Customizing QTabWidget for an example.

标签小部件的框架使用 ::pane 子控件进行样式设置。 左右角分别使用 ::left-corner 和 ::right-corner 进行样式设置。 标签栏的位置是使用 ::tab-bar 子控件控制的。 默认情况下,子控件在 QWindowsStyle 中具有 QTabWidget 的位置。 要将 QTabBar 置于中心,请设置标签栏子控件的子控件位置。 :top, :left, :right, :bottom 伪状态取决于选项卡的方向。 有关示例,请参阅自定义 QTabWidget。

QTableViewSupports the box model. When alternating row colors is enabled, the alternating colors can be styled using the alternate-background-color property.

The color and background of the selected item is styled using selection-color and selection-background-color respectively.

The corner widget in a QTableView is implemented as a QAbstractButton and can be styled using the "QTableView QTableCornerButton::section" selector.

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

The color of the grid can be specified using the gridline-color property.

See QAbsractScrollArea to style scrollable backgrounds.

See Customzing QTableView for an example.

支持盒子模型。 启用交替行颜色后,可以使用交替背景颜色属性设置交替颜色的样式。 所选项目的颜色和背景分别使用 selection-color 和 selection-background-color 设置样式。 QTableView 中的角小部件作为 QAbstractButton 实现,可以使用“QTableView QTableCornerButton::section”选择器设置样式。 警告:如果您只在 QTableCornerButton 上设置背景颜色,除非您将边框属性设置为某个值,否则背景可能不会出现。 这是因为,默认情况下, QTableCornerButton 绘制一个与背景颜色完全重叠的原生边框。 可以使用 gridline-color 属性指定网格的颜色。 请参阅 QAbsractScrollArea 以设置可滚动背景的样式。 有关示例,请参阅自定义 QTableView。

QTableWidgetSee QTableView.
QTextEditSupports the box model.

The color and background of selected text is styled using selection-color and selection-background-color respectively.

See QAbsractScrollArea to style scrollable backgrounds.

支持盒子模型。 所选文本的颜色和背景分别使用 selection-color 和 selection-background-color 设置样式。 请参阅 QAbsractScrollArea 以设置可滚动背景的样式。

QTimeEditSee QSpinBox.
QToolBarSupports the box model.

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).

The separator of a QToolBar is styled using the ::separator subcontrol.

The handle (to move the toolbar) is styled using the ::handle subcontrol.

See Customizing QToolBar for an example.

支持盒子模型。 :top, :left, :right, :bottom 伪状态取决于工具栏所在的区域。 :first、:last、:middle、:only-one 伪状态指示线组中工具栏的位置(请参阅 QStyleOptionToolBar::positionWithinLine)。 QToolBar 的分隔符使用 ::separator 子控件进行样式设置。 手柄(用于移动工具栏)使用 ::handle 子控件设置样式。 有关示例,请参阅自定义 QToolBar。

QToolButtonSupports the box model.

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.

Warning: 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; }

See Customizing QToolButton for an example.

支持盒子模型。 如果 QToolButton 有菜单, is ::menu-indicator 子控件可用于设置指示器的样式。默认情况下,菜单指示器位于小部件的 Padding 矩形的右下角。 如果 QToolButton 处于 QToolButton::MenuButtonPopup 模式,则使用 ::menu-button 子控件绘制菜单按钮。 ::menu-arrow 子控件用于在菜单按钮内绘制菜单箭头。默认情况下,它位于菜单按钮子控件的内容矩形的中心。 当 QToolButton 显示箭头时,会使用 ::up-arrow、::down-arrow、::left-arrow 和 ::right-arrow 子控件。 警告:如果您只在 QToolButton 上设置背景颜色,除非您将边框属性设置为某个值,否则背景不会出现。这是因为默认情况下,QToolButton 会绘制一个与背景颜色完全重叠的原生边框。例如, QToolButton { background-color: red; border: none; }有关示例,请参阅自定义 QToolButton。

QToolBoxSupports the box model.

The individual tabs can by styled using the ::tab subcontrol. The tabs support the :only-one:first:last:middle:previous-selected:next-selected:selected pseudo states.

支持盒子模型。 可以使用 ::tab 子控件设置各个选项卡的样式。 选项卡支持:only-one, :first, :last, :middle, :previous-selected, :next-selected, :selected 伪状态。

QToolTipSupports the box model. The opacity property controls the opacity of the tooltip.

See Customizing QFrame for an example (a QToolTip is a QFrame).

支持盒子模型。 opacity 属性控制工具提示的不透明度。 有关示例,请参阅自定义 QFrame(QToolTip 是 QFrame)。

QTreeViewSupports the box model. When alternating row colors is enabled, the alternating colors can be styled using the alternate-background-color property.

The color and background of the selected item is styled using selection-color and selection-background-color respectively.

The selection behavior is controlled by the show-decoration-selected property.

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 pseudo states.

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

See QAbsractScrollArea to style scrollable backgrounds.

See Customizing QTreeView for an example to style the branches.

支持盒子模型。 启用交替行颜色后,可以使用交替背景颜色属性设置交替颜色的样式。 所选项目的颜色和背景分别使用 selection-color 和 selection-background-color 设置样式。 选择行为由 show-decoration-selected 属性控制。 树视图的分支可以使用 ::branch 子控件进行样式设置。 ::branch 子控件支持 :open、:closed、:has-sibling 和 :has-children 伪状态。 使用 ::item 子控件对 QTreeView 中的项目进行更细粒度的控制。 请参阅 QAbsractScrollArea 以设置可滚动背景的样式。 有关设置分支样式的示例,请参阅自定义 QTreeView。

QTreeWidgetSee QTreeView.
QWidgetSupports only the backgroundbackground-clip and background-origin properties.

If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below:

仅支持背景、背景剪辑和背景原点属性。 如果您是 QWidget 的子类,则需要为您的自定义 QWidget 提供一个paintEvent,如下所示:

void CustomWidget::paintEvent(QPaintEvent *)
{
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

The above code is a no-operation if there is no stylesheet set.

Warning: Make sure you define the Q_OBJECT macro for your custom widget.

如果没有设置样式表,上面的代码是无操作的。 警告:确保为自定义小部件定义 Q_OBJECT 宏。

List of Properties属性列表

The table below lists all the properties supported by Qt Style Sheets. Which values can be given to an property depend on the property's type. Unless otherwise specified, properties below apply to all widgets. Properties marked with an asterisk * are specific to Qt and have no equivalent in CSS2 or CSS3.

下表列出了 Qt 样式表支持的所有属性。 可以为属性赋予哪些值取决于属性的类型。 除非另有说明,否则以下属性适用于所有小部件。 用星号 * 标记的属性是 Qt 特有的,在 CSS2 或 CSS3 中没有等效项。

属性类型描述
alternate-background-colorBrushThe alternate background color used in QAbstractItemView subclasses.

If this property is not set, the default value is whatever is set for the palette's AlternateBase role.

Example:

QAbstractItemView 子类中使用的备用背景颜色。 如果未设置此属性,

则默认值是为调色板的 AlternateBase 角色设置的任何值。 例子:

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

See also background and selection-background-color.

另请参阅背景和选择背景颜色。

backgroundBackgroundShorthand notation for setting the background. Equivalent to specifying background-colorbackground-imagebackground-repeat, and/or background-position.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQDialogQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEditQToolTip, and plain QWidgets.

Example:

用于设置背景的速记符号。 相当于指定背景颜色、背景图像、背景重复和/或背景位置。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QDialog、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSplitter、QTextEdit 和 QToolTWidget 支持此属性 例子:

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::SolidPatternQt::RadialGradientPatternQt::LinearGradientPattern and Qt::ConicalGradientPattern. The other patterns are easily achieved by creating a background image that contains the pattern.

Example:

通常,需要设置类似于 Qt::BrushStyle 中的样式的填充模式。 您可以为 Qt::SolidPattern、Qt::RadialGradientPattern、Qt::LinearGradientPattern 和 Qt::ConicalGradientPattern 使用背景颜色属性。 通过创建包含该图案的背景图像,可以轻松实现其他图案。 例子:

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

See also background-originselection-background-colorbackground-clipbackground-attachment and alternate-background-color.

background-colorBrushThe background color used for the widget.

Examples:

用于小部件的背景颜色。 例子:

QLabel { background-color: yellow }
QLineEdit { background-color: rgb(255, 0, 0) }
background-imageUrlThe background image used for the widget. Semi-transparent parts of the image let the background-color shine through.

Example:

用于小部件的背景图像。 图像的半透明部分让背景颜色闪耀。 例子:

QFrame { background-image: url(:/images/hydro.png) }
background-repeatRepeatWhether and how the background image is repeated to fill the background-origin rectangle.

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

Example:

是否以及如何重复背景图像以填充背景原点矩形。 如果未指定此属性,则背景图像在两个方向上重复(repeat)。 例子:

QFrame {
    background: white url(:/images/ring.png);
    background-repeat: repeat-y;
    background-position: left;
}
background-positionAlignmentThe alignment of the background image within the background-origin rectangle.

If this property is not specified, the alignment is top left.

Example:

背景图片在背景原点矩形内的对齐方式。 如果未指定此属性,则对齐方式为左上角。 例子:

QFrame {
    background: url(:/images/footer.png);
    background-position: bottom left;
}
background-attachmentAttachmentDetermines whether the background-image in a QAbstractScrollArea is scrolled or fixed with respect to the viewport. By default, the background-image scrolls with the viewport.

Example:

确定 QAbstractScrollArea 中的背景图像是相对于视口滚动还是固定。 默认情况下,背景图像随视口滚动。 例子:

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

See also background

background-clipOriginThe widget's rectangle, in which the background is drawn.

This property specifies the rectangle to which the background-color and background-image are clipped.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQDialogQFrameQGroupBoxQLabelQPushButtonQRadioButtonQSplitterQTextEditQToolTip, and plain QWidgets.

If this property is not specified, the default is border.

Example:

小部件的矩形,其中绘制了背景。 此属性指定背景颜色和背景图像被剪切到的矩形。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QDialog、QFrame、QGroupBox、QLabel、QPushButton、QRadioButton、QSplitter、QTextEdit、QToolTip 和普通 QWidget 支持此属性。 如果未指定此属性,则默认为边框。 例子:

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

See also backgroundbackground-origin and The Box Model.

background-originOriginThe widget's background rectangle, to use in conjunction with background-position and background-image.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQDialogQFrameQGroupBoxQLabelQPushButtonQRadioButtonQSplitterQTextEditQToolTip, and plain QWidgets.

If this property is not specified, the default is padding.

Example:

小部件的背景矩形,与背景位置和背景图像结合使用。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QDialog、QFrame、QGroupBox、QLabel、QPushButton、QRadioButton、QSplitter、QTextEdit、QToolTip 和普通 QWidget 支持此属性。 如果未指定此属性,则默认为填充。 例子:

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

See also background and The Box Model.

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

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEditQToolTip, and plain QWidgets.

Example:

用于设置小部件边框的速记符号。 相当于指定边框颜色、边框样式和/或边框宽度。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSplitter、QTextEdit、QToolQWidgets 和普通支持此属性。 例子:

QLineEdit { border: 1px solid white }
border-topBorder

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

用于设置小部件顶部边框的速记符号。 相当于指定 border-top-color、border-top-style 和/或 border-top-width。

border-rightBorder

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

用于设置小部件右边框的速记符号。 相当于指定 border-right-color、border-right-style 和/或 border-right-width。

border-bottomBorder

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

用于设置小部件底部边框的速记符号。 相当于指定 border-bottom-color、border-bottom-style 和/或 border-bottom-width。

border-leftBorder

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

用于设置小部件左边框的速记符号。 相当于指定border-left-color、border-left-style和/或border-left-width。

border-colorBox ColorsThe color of all the border's edges. Equivalent to specifying border-top-colorborder-right-colorborder-bottom-color, and border-left-color.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEditQToolTip, and plain QWidgets.

If this property is not specified, it defaults to color (i.e., the widget's foreground color).

Example:

所有边框边缘的颜色。 相当于指定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、QToolQWidgets 和普通支持此属性。 如果未指定此属性,则默认为颜色(即小部件的前景色)。 例子:

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

See also border-styleborder-widthborder-image, and The Box Model.

border-top-colorBrushThe color of the border's top edge.边框顶部边缘的颜色。
border-right-colorBrushThe color of the border's right edge.边框右边缘的颜色。
border-bottom-colorBrushThe color of the border's bottom edge.边框底部边缘的颜色。
border-left-colorBrushThe color of the border's left edge.边框左边缘的颜色。
border-imageBorder ImageThe image used to fill the border. The image is cut into nine parts and stretched appropriately if necessary. See Border Image for details.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEdit and QToolTip.

See also border-colorborder-styleborder-width, and The Box Model.

用于填充边框的图像。 图像被切割成九个部分,并在必要时适当拉伸。 有关详细信息,请参阅边框图片。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSplitter、QTextEdit 和 QToolTip 支持此属性。 另请参阅边框颜色、边框样式、边框宽度和盒子模型。

border-radiusRadiusThe radius of the border's corners. Equivalent to specifying border-top-left-radiusborder-top-right-radiusborder-bottom-right-radius, and border-bottom-left-radius.

The border-radius clips the element's background.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEdit, and QToolTip.

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

Example:

边界角的半径。 相当于指定border-top-left-radius、border-top-right-radius、border-bottom-right-radius和border-bottom-left-radius。 border-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;
}

See also border-width and The Box Model.

另请参阅边框宽度和盒子模型。

border-top-left-radiusRadius

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

边框左上角的半径。

border-top-right-radiusRadius

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

边框右上角的半径。

border-bottom-right-radiusRadius

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

边框右下角的半径。 将此属性设置为正值会导致圆角。

border-bottom-left-radiusRadius

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

边框左下角的半径。 将此属性设置为正值会导致圆角。

border-styleBorder StyleThe style of all the border's edges.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEdit, and QToolTip.

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

Example:

所有边框边缘的样式。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSplitter、QTextEdit 和 QToolTip 支持此属性。 如果未指定此属性,则默认为无。 例子:

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

See also border-colorborder-styleborder-image, and The Box Model.

border-top-styleBorder StyleThe style of the border's top edge.边框顶部边缘的样式。
border-right-styleBorder StyleThe style of the border's right edge/边框右边缘的样式/
border-bottom-styleBorder StyleThe style of the border's bottom edge.边框底部边缘的样式。
border-left-styleBorder StyleThe style of the border's left edge.边框左边缘的样式。
border-widthBox LengthsThe width of the border. Equivalent to setting border-top-widthborder-right-widthborder-bottom-width, and border-left-width.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEdit, and QToolTip.

Example:

边框的宽度。 相当于设置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;
}

See also border-colorborder-radiusborder-styleborder-image, and The Box Model.

border-top-widthLengthThe width of the border's top edge.边框顶部边缘的宽度。
border-right-widthLengthThe width of the border's right edge.边框右边缘的宽度。
border-bottom-widthLengthThe width of the border's bottom edge.边框底部边缘的宽度。
border-left-widthLengthThe width of the border's left edge.边框左边缘的宽度。
bottomLengthIf position is relative (the default), moves a subcontrol by a certain offset up; specifying bottom: y is then equivalent to specifying top: -y.

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

Example:

如果位置是相对的(默认),则将子控件向上移动一定的偏移量; 指定底部:y 则等效于指定顶部:-y。 如果 position 是绝对的,则底部属性指定子控件相对于父控件底部边缘的底部边缘(另请参阅 subcontrol-origin)。 例子:

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

如果位置是相对的(默认),则将子控件向上移动一定的偏移量; 指定底部:y 则等效于指定顶部:-y。 如果 position 是绝对的,则底部属性指定子控件相对于父控件底部边缘的底部边缘(另请参阅 subcontrol-origin)。 例子: QSpinBox::down-button { bottom: 2px }

See also leftright, and top.

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

If this property is not specified, it defaults to the value specified by the current style for the SH_DialogButtonLayout style hint.

Example:

QDialogButtonBox 或 QMessageBox 中按钮的布局。 可能的值为 0 (WinLayout)、1 (MacLayout)、2 (KdeLayout)、3 (GnomeLayout) 和 5 (AndroidLayout)。 如果未指定此属性,则默认为 SH_DialogButtonLayout 样式提示的当前样式指定的值。 例子:

* { button-layout: 2 }
colorBrushThe color used to render text.

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).

Example:

用于呈现文本的颜色。 所有尊重 QWidget::palette 的小部件都支持此属性。 如果未设置此属性,则默认值为小部件调色板中为 QWidget::foregroundRole 设置的任何内容(通常为黑色)。 例子:

QPushButton { color: red }

See also background and selection-color.

dialogbuttonbox-buttons-have-iconsBooleanWhether 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.

See the List of Icons section for information on how to set icons.

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

Note: 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.

QDialogButtonBox 中的按钮是否显示图标 如果此属性设置为 1,则 QDialogButtonBox 的按钮显示图标; 如果设置为 0,则不显示图标。 有关如何设置图标的信息,请参阅图标列表部分。 QDialogButtonBox { dialogbuttonbox-buttons-have-icons: 1; } 注意:定义此属性的样式必须在创建 QDialogButtonBox 之前应用; 这意味着您必须将样式应用到父小部件或应用程序本身。

fontFontShorthand notation for setting the text's font. Equivalent to specifying font-familyfont-sizefont-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.

Example:

用于设置文本字体的速记符号。 相当于指定 font-family、font-size、font-style 和/或 font-weight。 所有尊重 QWidget::font 的小部件都支持此属性。 如果未设置此属性,则默认为 QWidget::font。 例子:

QCheckBox { font: bold italic large "Times New Roman" }
font-familyStringThe font family.字体家族。

Example:

QCheckBox { font-family: "New Century Schoolbook" }
font-sizeFont Size

The font size. In this version of Qt, only pt and px metrics are supported.

字体大小。 在此版本的 Qt 中,仅支持 pt 和 px 指标。

Example:

QTextEdit { font-size: 12px }
font-styleFont StyleThe font style.字体样式。

Example:

QTextEdit { font-style: italic }
font-weightFont WeightThe weight of the font.字体的粗细。
gridline-color*ColorThe color of the grid line in a QTableView.

If this property is not specified, it defaults to the value specified by the current style for the SH_Table_GridLineColor style hint.

Example:

QTableView 中网格线的颜色。 如果未指定此属性,则默认为当前样式为 SH_Table_GridLineColor 样式提示指定的值。 例子:

* { gridline-color: gray }
heightLengthThe height of a subcontrol (or in some case, a widget).

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

Warning: 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.

子控件(或在某些情况下是小部件)的高度。 如果未指定此属性,则默认为取决于子控件/小部件和当前样式的值。 警告:除非另有说明,否则此属性在小部件上设置时无效。 如果您想要一个具有固定高度的小部件,请将 min-height 和 max-height 设置为相同的值。

Example:

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

See also width.

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

The only widget currently supporting this property is QPushButton.

Note: It's the application's responsibilty 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.

Available since 5.15.

用于具有图标的小部件的图标。 当前唯一支持此属性的小部件是 QPushButton。 注意:为按钮分配图标(使用 QAbstractButton API)是应用程序的责任,而不是样式的责任。 因此,除非您的样式表针对特定应用程序,否则请小心设置它。 自 5.15 起可用。

icon-sizeLengthThe width and height of the icon in a widget.

The icon size of the following widgets can be set using this property.

小部件中图标的宽度和高度。 可以使用此属性设置以下小部件的图标大小。

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

The image property accepts a list of Urls 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.

Warning: The QIcon SVG plugin is needed to render SVG images.

在子控件的内容矩形中绘制的图像。 image 属性接受 URL 列表或 svg。 绘制的实际图像使用与 QIcon 相同的算法确定(即图像从不放大,但在必要时总是缩小。 如果指定了 svg,则图像将缩放到内容矩形的大小。 在子控件上设置图像属性会隐式设置子控件的宽度和高度(除非图像在 SVG 中)。 在 Qt 4.3 及更高版本中,可以使用 image-position 指定矩形内图像的对齐方式。 此属性仅适用于子控件——我们不支持其他元素使用它。 警告:渲染 SVG 图像需要 QIcon SVG 插件。

Example:

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

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

在 Qt 4.3 及更高版本中,可以使用相对或绝对位置指定图像图像位置的对齐方式。

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

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

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

如果 position 是相对的(默认),则将子控件向右移动一定的偏移量。 如果 position 是绝对的,则 left 属性指定子控件相对于父控件左边缘的左边缘(另请参阅 subcontrol-origin)。

如果未指定此属性,则默认为 0。

Example:

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

See also righttop, and bottom.

lineedit-password-character*NumberThe QLineEdit password character as a Unicode number.

If this property is not specified, it defaults to the value specified by the current style for the SH_LineEdit_PasswordCharacter style hint.

QLineEdit 密码字符作为 Unicode 数字。 如果未指定此属性,则默认为 SH_LineEdit_PasswordCharacter 样式提示的当前样式指定的值。

Example:

* { lineedit-password-character: 9679 }
lineedit-password-mask-delay*NumberThe QLineEdit password mask delay in milliseconds before lineedit-password-character is applied to visible character.

If this property is not specified, it defaults to the value specified by the current style for the SH_LineEdit_PasswordMaskDelay style hint.

This property was added in Qt 5.4.

在将 lineedit-password-character 应用于可见字符之前,QLineEdit 密码掩码延迟(以毫秒为单位)。 如果未指定此属性,则默认为 SH_LineEdit_PasswordMaskDelay 样式提示的当前样式指定的值。

这个属性是在 Qt 5.4 中添加的。

Example:

* { lineedit-password-mask-delay: 1000 }
marginBox LengthsThe widget's margins. Equivalent to specifying margin-topmargin-rightmargin-bottom, and margin-left.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEdit, and QToolTip.

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

小部件的边距。 相当于指定 margin-top、margin-right、margin-bottom 和 margin-left。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSplitter、QTextEdit 和 QToolTip 支持此属性。 如果未指定此属性,则默认为 0。

Example:

QLineEdit { margin: 2px }

See also paddingspacing, and The Box Model.

margin-topLengthThe widget's top margin.小部件的上边距。
margin-rightLengthThe widget's right margin.小部件的右边距。
margin-bottomLengthThe widget's bottom margin.小部件的底部边距。
margin-leftLengthThe widget's left margin.小部件的左边距。
max-heightLengthThe widget's or a subcontrol's maximum height.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSizeGripQSpinBoxQSplitterQStatusBarQTextEdit, and QToolTip.

The value is relative to the contents rect in the box model.

小部件或子控件的最大高度。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSizeGrip、QSpinBox、QTextEdit、QStatus、QStatus 支持此属性。 该值与框模型中的内容 rect 相关。

Example:

QSpinBox { max-height: 24px }

See also max-width.

max-widthLengthThe widget's or a subcontrol's maximum width.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSizeGripQSpinBoxQSplitterQStatusBarQTextEdit, and QToolTip.

The value is relative to the contents rect in the box model.

小部件或子控件的最大宽度。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSizeGrip、QSpinBox、QTextEdit、QStatus、QStatus 支持此属性。 该值与框模型中的内容 rect 相关。

 

Example:

QComboBox { max-width: 72px }

See also max-height.

messagebox-text-interaction-flags*NumberThe interaction behavior for text in a message box. Possible values are based on Qt::TextInteractionFlags.

If this property is not specified, it defaults to the value specified by the current style for the SH_MessageBox_TextInteractionFlags style hint.

消息框中文本的交互行为。 可能的值基于 Qt::TextInteractionFlags。 如果未指定此属性,则默认为当前样式为 SH_MessageBox_TextInteractionFlags 样式提示指定的值。

Example:

QMessageBox { messagebox-text-interaction-flags: 5 }
min-heightLengthThe widget's or a subcontrol's minimum height.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSizeGripQSpinBoxQSplitterQStatusBarQTextEdit, and 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 model.

小部件或子控件的最小高度。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSizeGrip、QSpinBox、QTextEdit、QStatus、QStatus 支持此属性。 如果未指定此属性,则根据小部件的内容和样式得出最小高度。 该值与框模型中的内容 rect 相关。

Example:

QComboBox { min-height: 24px }

See also min-width.

min-widthLengthThe widget's or a subcontrol's minimum width.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSizeGripQSpinBoxQSplitterQStatusBarQTextEdit, and 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 model.

小部件或子控件的最小宽度。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSizeGrip、QSpinBox、QTextEdit、QStatus、QStatus 支持此属性。 如果未指定此属性,则根据小部件的内容和样式派生最小宽度。 该值与框模型中的内容 rect 相关。

Example:

QComboBox { min-width: 72px }

See also min-height.

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

If this property is not specified, it defaults to the value specified by the current style for the SH_ToolTipLabel_Opacity style hint.

小部件的不透明度。 可能的值是从 0(透明)到 255(不透明)。 目前,这仅支持工具提示。 如果未指定此属性,则默认为 SH_ToolTipLabel_Opacity 样式提示的当前样式指定的值。

Example:

QToolTip { opacity: 223 }
outline The outline drawn around the object's border.围绕对象边框绘制的轮廓。
outline-colorColorThe color of the outline. See also border-color轮廓的颜色。 另请参阅边框颜色
outline-offsetLengthThe outline's offset from the border of the widget.轮廓与小部件边框的偏移量。
outline-style 

Specifies the pattern used to draw the outline. See also border-style

指定用于绘制轮廓的图案。 另请参阅边框样式

outline-radius Adds rounded corners to the outline为轮廓添加圆角
outline-bottom-left-radiusRadius

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

轮廓左下角圆角的半径。

outline-bottom-right-radiusRadius

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

轮廓右下角圆角的半径。

outline-top-left-radiusRadius

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

轮廓左上角的半径。

outline-top-right-radiusRadius

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

轮廓右上角圆角的半径。

paddingBox LengthsThe widget's padding. Equivalent to specifying padding-toppadding-rightpadding-bottom, and padding-left.

This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBoxQComboBoxQFrameQGroupBoxQLabelQLineEditQMenuQMenuBarQPushButtonQRadioButtonQSplitterQTextEdit, and QToolTip.

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

小部件的填充。 相当于指定 padding-top、padding-right、padding-bottom 和 padding-left。 QAbstractItemView 子类、QAbstractSpinBox 子类、QCheckBox、QComboBox、QFrame、QGroupBox、QLabel、QLineEdit、QMenu、QMenuBar、QPushButton、QRadioButton、QSplitter、QTextEdit 和 QToolTip 支持此属性。 如果未指定此属性,则默认为 0。

Example:

QLineEdit { padding: 3px }

See also marginspacing, and The Box Model.

padding-topLengthThe widget's top padding.小部件的顶部填充。
padding-rightLengthThe widget's right padding.小部件的右侧填充。
padding-bottomLengthThe widget's bottom padding.小部件的底部填充。
padding-leftLengthThe widget's left padding.小部件的左侧填充。
paint-alternating-row-colors-for-empty-areabool

Whether the QTreeView paints alternating row colors for the empty area (i.e the area where there are no items)

QTreeView 是否为空白区域(即没有项目的区域)绘制交替的行颜色

positionrelative
absolute
Whether offsets specified using leftrighttop, and bottom are relative or absolute coordinates.

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

使用左、右、顶和底指定的偏移量是相对坐标还是绝对坐标。 如果未指定此属性,则默认为相对。

rightLengthIf 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.

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

如果 position 是相对的(默认),则将子控件向左移动一定的偏移量; 指定 right: x 等效于指定 left: -x。 如果 position 是绝对的,

则 right 属性指定子控件相对于父控件右边缘的右边缘(另请参阅 subcontrol-origin)。

Example:

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

See also lefttop, and bottom.

selection-background-color*BrushThe background of selected text or items.

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

If this property is not set, the default value is whatever is set for the palette's Highlight role.

所选文本或项目的背景。 所有尊重 QWidget::palette 并显示选择文本的小部件都支持此属性。

如果未设置此属性,则默认值是为调色板的突出显示角色设置的任何值。

Example:

QTextEdit { selection-background-color: darkblue }

See also selection-color and background.

selection-color*BrushThe foreground of selected text or items.

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

If this property is not set, the default value is whatever is set for the palette's HighlightedText role.

所选文本或项目的前景。 所有尊重 QWidget::palette 并显示选择文本的小部件都支持此属性。 如果未设置此属性,

则默认值是为调色板的 HighlightedText 角色设置的任何值。

Example:

QTextEdit { selection-color: white }

See also selection-background-color and color.

show-decoration-selected*BooleanControls whether selections in a QListView cover the entire row or just the extent of the text.

If this property is not specified, it defaults to the value specified by the current style for the SH_ItemView_ShowDecorationSelected style hint.

控制 QListView 中的选择是覆盖整行还是仅覆盖文本的范围。 如果未指定此属性,

则默认为 SH_ItemView_ShowDecorationSelected 样式提示的当前样式指定的值。

Example:

* { show-decoration-selected: 1 }
spacing*LengthInternal spacing in the widget.

This property is supported by QCheckBox, checkable QGroupBoxes, QMenuBar, and QRadioButton.

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

小部件中的内部间距。 QCheckBox、可检查的 QGroupBoxes、QMenuBar 和 QRadioButton 支持此属性。

如果未指定此属性,则默认值取决于小部件和当前样式。

Example:

QMenuBar { spacing: 10 }

See also padding and margin.

subcontrol-origin*OriginThe origin rectangle of the subcontrol within the parent element.

If this property is not specified, the default is padding.

父元素内子控件的原点矩形。 如果未指定此属性,则默认为填充。

Example:

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

See also subcontrol-position.

subcontrol-position*AlignmentThe 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.

子控件在 subcontrol-origin 指定的原点矩形内的对齐方式。

如果未指定此属性,则默认为取决于子控件的值。

Example:

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

See also subcontrol-origin.

titlebar-show-tooltips-on-buttons}bool

Whether tool tips are shown on window title bar buttons.

工具提示是否显示在窗口标题栏按钮上。

widget-animation-duration*NumberHow much an animation should last (in milliseconds). A value equal to zero means that the animations will be disabled.

If this property is not specified, it defaults to the value specified by the current style for the SH_Widget_Animation_Duration style hint.

This property was added in Qt 5.10.

动画应该持续多长时间(以毫秒为单位)。 值为零意味着动画将被禁用。 如果未指定此属性,

则默认为 SH_Widget_Animation_Duration 样式提示的当前样式指定的值。 这个属性是在 Qt 5.10 中添加的。

Example:

* { widget-animation-duration: 100 }
text-alignAlignmentThe 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.

小部件内容中文本和图标的对齐方式。 如果未指定此值,则默认为取决于本机样式的值。

Example:

QPushButton {
    text-align: left;
}

This property is currently supported only by QPushButton and QProgressBar.

text-decorationnone
underline
overline
line-through
Additional text effects附加文字效果
topLengthIf position is relative (the default), moves a subcontrol by a certain offset down.

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

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

如果 position 是相对的(默认),则将子控件向下移动一定的偏移量。 如果 position 是绝对的,则 top 属性指定子控件相对于父控件的顶部边缘的顶部边缘

(另请参阅 subcontrol-origin)。 如果未指定此属性,则默认为 0。

Example:

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

See also leftright, and bottom.

widthLengthThe 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.

Warning: 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.

子控件(或某些情况下的小部件)的宽度。 如果未指定此属性,则默认为取决于子控件/小部件和当前样式的值。 警告:除非另有说明,否则此属性在小部件上设置时无效。 如果您想要一个固定宽度的小部件,请将 min-width 和 max-width 设置为相同的值。

 

Example:

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

See also height.

-qt-background-rolePaletteRole

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

基于所选角色的子控件或小部件的背景颜色。

-qt-style-featureslistThe list of CSS properties that you want to apply Qt-specific styles on.

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

要应用 Qt 特定样式的 CSS 属性列表。 注意:该列表只能包含不基于像素图的属性。

 

图标列表:

Qt中使用的图标可以使用以下属性进行自定义。本节中列出的每个属性都有类型图标。

请注意,要使图标出现在 QDialogButtonBox 的按钮中,您需要将 dialogbuttonbox-buttons-have-icons 属性设置为 true。 此外,要自定义图标的大小,请使用 icon-size 属性。

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

 

属性类型列表:

下表总结了不同属性类型的语法和含义。

TypeSyntaxDescription
Alignmenttop
bottom
left
right
center }*
Horizontal and/or vertical alignment.

Example:

QTextEdit { background-position: bottom center }
Attachmentscroll
fixed }*
Scroll or fixed attachment.
BackgroundBrush
Url
Repeat
Alignment }*
A sequence of BrushUrlRepeat, and Alignment.
Boolean0 | 1True (1) or false (0).

Example:

QDialog { etch-disabled-text: 1 }
BorderBorder Style
Length
Brush }*
Shorthand border property.
Border Imagenone
Url Number{4}
(stretch | repeat){0,2}
边框图像是由九个部分组成的图像(左上、中上、右上、左中、中、右中、左下、中下和右下)。当需要一定尺寸的边框时,角部按原样使用,顶部、右侧、底部和左侧部分拉伸或重复以生成所需尺寸的边框。

See the CSS3 Draft Specification for details.

Border Styledashed
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.指定用于绘制边框的图案。 有关详细信息,请参阅 CSS3 草案规范。
Box ColorsBrush{1,4}一到四次 笔刷,分别指定长方体的上、右、下和左边缘。如果未指定左颜色,则认为它与右颜色相同。如果未指定底色,则认为底色与顶色相同。如果未指定正确的颜色,则视为与顶部颜色相同。

Example:

QLabel { border-color: red }   /* red red red red */
QLabel { border-color: red blue } /* red blue red blue */
QLabel { border-color: red blue green } /* red blue green blue */
QLabel { border-color: red blue green yellow }
/* red blue green yellow */
Box LengthsLength{1,4}One to four occurrences of Length, 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.

Examples:

QLabel { border-width: 1px }                    /* 1px 1px 1px 1px */
QLabel { border-width: 1px 2px }                /* 1px 2px 1px 2px */
QLabel { border-width: 1px 2px 3px }            /* 1px 2px 3px 2px */
QLabel { border-width: 1px 2px 3px 4px }        /* 1px 2px 3px 4px */
BrushColor
Gradient
PaletteRole
Specifies a Color or a Gradient or an entry in the Palette.
Colorrgb(rgb)
rgba(rgba)
hsv(hsv)
hsva(hsva)
hsl(hsl)
hsla(hsla)
#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.

Examples:

QLabel { border-color: red }                      /* opaque red */
QLabel { border-color: #FF0000 }                  /* opaque red */
QLabel { border-color: rgba(255, 0, 0, 75%) }     /* 75% opaque red */
QLabel { border-color: rgb(255, 0, 0) }           /* opaque red */
QLabel { border-color: rgb(100%, 0%, 0%) }        /* opaque red */
QLabel { border-color: hsv(60, 100%, 100%) }      /* opaque yellow */
QLabel { border-color: hsva(240, 255, 255, 75%) } /* 75% blue */
QLabel { border-color: hsl(60, 100%, 50%) }       /* opaque yellow */
QLabel { border-color: hsla(240, 255, 50%, 75%) } /* 75% blue */

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

Font(Font Style | Font Weight){0,2} Font Size StringShorthand font property.
Font SizeLengthThe size of a font.
Font Stylenormal
italic
oblique
The style of a font.
Font Weightnormal
bold
100
200
...
900
The weight of a font.
Gradientqlineargradient
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).

Warning: The stops have to appear sorted in ascending order.

Examples:

/* 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)
}
Icon(Url (disabled | active | normal | selected)? (on | off)? )*A list of url, QIcon::Mode and QIcon::State.

Example:

* {
    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;
}
LengthNumber (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 em width of the font (i.e., the width of 'M')
  • 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 pxem or ex.

NumberA decimal integer or a real numberExamples: 018+127-25512.34-.50009.
Originmargin
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.

See also The Box Model.

PaletteRolealternate-base
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.

For example,

QPushButton { color: palette(dark); }
RadiusLength{1, 2}One or two occurrences of Length. 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.
Repeatrepeat-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.
Urlurl(filename)filename is the name of a file on the local disk or stored using The Qt Resource System. Setting an image implicitly sets the width and height of the element.

 

伪状态列表

支持以下伪状态::

Pseudo-StateDescription
:activeThis state is set when the widget resides in an active window.
:adjoins-itemThis state is set when the ::branch of a QTreeView is adjacent to an item.
:alternateThis state is set for every alternate row whe painting the row of a QAbstractItemView when QAbstractItemView::alternatingRowColors() is set to true.
:bottomThe item is positioned at the bottom. For example, a QTabBar that has its tabs positioned at the bottom.
:checkedThe item is checked. For example, the checked state of QAbstractButton.
:closableThe items can be closed. For example, the QDockWidget has the QDockWidget::DockWidgetClosable feature turned on.
:closedThe item is in the closed state. For example, an non-expanded item in a QTreeView
:defaultThe item is the default. For example, a default QPushButton or a default action in a QMenu.
:disabledThe item is disabled.
:editableThe QComboBox is editable.
:edit-focusThe item has edit focus (See QStyle::State_HasEditFocus). This state is available only for Qt Extended applications.
:enabledThe item is enabled.
:exclusiveThe item is part of an exclusive item group. For example, a menu item in a exclusive QActionGroup.
:firstThe item is the first (in a list). For example, the first tab in a QTabBar.
:flatThe item is flat. For example, a flat QPushButton.
:floatableThe items can be floated. For example, the QDockWidget has the QDockWidget::DockWidgetFloatable feature turned on.
:focusThe item has input focus.
:has-childrenThe item has children. For example, an item in a QTreeView that has child items.
:has-siblingsThe item has siblings. For example, an item in a QTreeView that siblings.
:horizontalThe item has horizontal orientation
:hoverThe mouse is hovering over the item.
:indeterminateThe item has indeterminate state. For example, a QCheckBox or QRadioButton is partially checked.
:lastThe item is the last (in a list). For example, the last tab in a QTabBar.
:leftThe item is positioned at the left. For example, a QTabBar that has its tabs positioned at the left.
:maximizedThe item is maximized. For example, a maximized QMdiSubWindow.
:middleThe item is in the middle (in a list). For example, a tab that is not in the beginning or the end in a QTabBar.
:minimizedThe item is minimized. For example, a minimized QMdiSubWindow.
:movableThe item can be moved around. For example, the QDockWidget has the QDockWidget::DockWidgetMovable feature turned on.
:no-frameThe item has no frame. For example, a frameless QSpinBox or QLineEdit.
:non-exclusiveThe item is part of a non-exclusive item group. For example, a menu item in a non-exclusive QActionGroup.
:offFor items that can be toggled, this applies to items in the "off" state.
:onFor items that can be toggled, this applies to widgets in the "on" state.
:only-oneThe item is the only one (in a list). For example, a lone tab in a QTabBar.
:openThe item is in the open state. For example, an expanded item in a QTreeView, or a QComboBox or QPushButton with an open menu.
:next-selectedThe next item (in a list) is selected. For example, the selected tab of a QTabBar is next to this item.
:pressedThe item is being pressed using the mouse.
:previous-selectedThe previous item (in a list) is selected. For example, a tab in a QTabBar that is next to the selected tab.
:read-onlyThe item is marked read only or non-editable. For example, a read only QLineEdit or a non-editable QComboBox.
:rightThe item is positioned at the right. For example, a QTabBar that has its tabs positioned at the right.
:selectedThe item is selected. For example, the selected tab in a QTabBar or the selected item in a QMenu.
:topThe item is positioned at the top. For example, a QTabBar that has its tabs positioned at the top.
:uncheckedThe item is unchecked.
:verticalThe item has vertical orientation.
:windowThe widget is a window (i.e top level widget)

 

子控件列表

以下子控件可用:

Sub-ControlDescription
::add-lineThe button to add a line of a QScrollBar.
::add-pageThe region between the handle (slider) and the add-line of a QScrollBar.
::branchThe branch indicator of a QTreeView.
::chunkThe progress chunk of a QProgressBar.
::close-buttonThe close button of a QDockWidget or tabs of QTabBar
::cornerThe corner between two scrollbars in a QAbstractScrollArea
::down-arrowThe down arrow of a QComboBoxQHeaderView (sort indicator), QScrollBar or QSpinBox.
::down-buttonThe down button of a QScrollBar or a QSpinBox.
::drop-downThe drop-down button of a QComboBox.
::float-buttonThe float button of a QDockWidget
::grooveThe groove of a QSlider.
::indicatorThe indicator of a QAbstractItemView, a QCheckBox, a QRadioButton, a checkable QMenu item or a checkable QGroupBox.
::handleThe handle (slider) of a QScrollBar, a QSplitter, or a QSlider.
::iconThe icon of a QAbstractItemView or a QMenu.
::itemAn item of a QAbstractItemView, a QMenuBar, a QMenu, or a QStatusBar.
::left-arrowThe left arrow of a QScrollBar.
::left-cornerThe left corner of a QTabWidget. For example, this control can be used to control position the left corner widget in a QTabWidget.
::menu-arrowThe arrow of a QToolButton with a menu.
::menu-buttonThe menu button of a QToolButton.
::menu-indicatorThe menu indicator of a QPushButton.
::right-arrowThe right arrow of a QMenu or a QScrollBar.
::paneThe pane (frame) of a QTabWidget.
::right-cornerThe right corner of a QTabWidget. For example, this control can be used to control the position the right corner widget in a QTabWidget.
::scrollerThe scroller of a QMenu or QTabBar.
::sectionThe section of a QHeaderView.
::separatorThe separator of a QMenu or in a QMainWindow.
::sub-lineThe button to subtract a line of a QScrollBar.
::sub-pageThe region between the handle (slider) and the sub-line of a QScrollBar.
::tabThe tab of a QTabBar or QToolBox.
::tab-barThe tab bar of a QTabWidget. This subcontrol exists only to control the position of the QTabBar inside the QTabWidget. To style the tabs using the ::tab subcontrol.
::tearThe tear indicator of a QTabBar.
::tearoffThe tear-off indicator of a QMenu.
::textThe text of a QAbstractItemView.
::titleThe title of a QGroupBox or a QDockWidget.
::up-arrowThe up arrow of a QHeaderView (sort indicator), QScrollBar or a QSpinBox.
::up-buttonThe up button of a QSpinBox.

 

 

 

标签:控件,Style,Qt,color,样式表,background,subcontrol,property,border
来源: https://blog.csdn.net/weixin_40583088/article/details/118003991

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有