属性列表
下表列出了Qt样式表支持的所有属性。可以为属性赋予哪些值取决于属性的类型。除非另有说明,否则以下属性适用于所有小部件。标有星号*的属性特定于Qt,在CSS2或CSS3中没有等效项。
Property | Type | Description |
---|---|---|
alternate-background-color | Brush | QAbstractItemView 子类的交替背景颜色(偶数行). 如果未设置此属性,则默认值为为调色板的AlternateBase角色设置的值. 例: QTreeView { alternate-background-color: blue; background: yellow; } |
background | Background | 用于设置背景的简写表示法。相当于指定background-color ,background-image ,background-repeat ,和/或background-position 。 QAbstractItemView子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QDialog,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton, QRadioButton,QSplitter,QTextEdit,QToolTip和普通QWidget支持此属性. 例: QTextEdit { background: yellow } 如果需要设置类似于Qt :: BrushStyle中的样式的填充模式。您可以使用Qt :: SolidPattern,Qt :: RadialGradientPattern,Qt :: LinearGradientPattern和Qt :: ConicalGradientPattern 的background-color属性。 通过创建包含图案的背景图像,可以轻松实现其他图案. 例: QLabel { background-image: url(dense6pattern.png); background-repeat: repeat-xy; } |
background-color | Brush | 用于窗口的背景颜色. 例: QLabel { background-color: yellow } QLineEdit { background-color: rgb(255, 0, 0) } |
background-image | Url | 用于窗口小部件的背景图像。图像的半透明部分让background-color 光泽透过. 例: QFrame { background-image: url(:/images/hydro.png) } |
background-repeat | Repeat | 定义了图像的平铺模式,是否以及如何重复背景图像以填充background-origin 矩形. 如果未指定此属性,则会在两个方向( 例: QFrame { background: white url(:/images/ring.png); background-repeat: repeat-y; background-position: left; } |
background-position | Alignment | background-origin 矩形内背景图像的对齐方式。 如果未指定此属性,则对齐为 例: QFrame { background: url(:/images/footer.png); background-position: bottom left; } |
background-attachment | Attachment | 确定QAbstractScrollArea中的背景图像是相对于视口滚动还是固定的。默认情况下,background-image使用视口滚动. 例: QTextEdit { background-image: url("leaves.png"); background-attachment: fixed; } |
background-clip | Origin | 指定background背景绘制区域. 指定剪切 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; } 其关键字是指将背景图片以border的尺寸、以padding的尺寸,以content的尺寸进行切割,其得到的结果是不完整的背景,也就是其中的一部分(原理与截图差不多)。 background-clip的切割是对这个容器背景的切割(包括图片与背景颜色)。 |
background-origin | Origin | 指定背景区域 。
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; } 其关键字是指将背景图片放置到border范围内,padding范围内、content范围内,其得到的结果是完整的背景(原理与图片的缩放相似)。只是单纯设置背景图片的边界,并不会对背景颜色造成影响 |
border | Border | 用于设置Widget边框的简写表示法。相当于指定border-color ,, border-style 和/或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 | 用于设置Widget顶部边框的简写表示法。相当于指定border-top-color , border-top-style , 和/或 border-top-width . |
border-right | Border | 用于设置Widget右边框的简写表示法。相当于指定border-right-color , border-right-style , 和/或 border-right-width . |
border-bottom | Border | 用于设置Widget底部边框的简写表示法。相当于指定border-bottom-color , border-bottom-style , 和/或 border-bottom-width . |
border-left | Border | 用于设置Widget左边框的简写表示法。相当于指定border-left-color , border-left-style , 和/或 border-left-width . |
border-color | Box Colors | 所有边框边缘的颜色。等效于声明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 (即窗口小部件的前景色). 例: QLineEdit { border-width: 1px; border-style: solid; border-color: white; } |
border-top-color | Brush | 边框顶部边缘的颜色. |
border-right-color | Brush | 边框右边缘的颜色. |
border-bottom-color | Brush | 边框底边的颜色. |
border-left-color | Brush | 边框左边缘的颜色. |
border-image | Border Image | 用于填充边框的图像。将图像切割成九个部分并在必要时适当拉伸。有关详情,请参见边框图 此属性支持QAbstractItemView中的子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit和QToolTip |
border-radius | Radius | 边界角的半径。等效于声明border-top-left-radius ,border-top-right-radius ,border-bottom-right-radius ,和border-bottom-left-radius 。 此属性支持QAbstractItemView中的子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit和QToolTip。 如果未指定此属性,则默认为0。 例: QLineEdit { border-width: 1px; border-style: solid; border-radius: 4px; } |
border-top-left-radius | Radius | 边框左上角的半径. |
border-top-right-radius | Radius | 边框右上角的半径. |
border-bottom-right-radius | Radius | 边框右下角的半径。将此属性设置为正值会产生圆角. |
border-bottom-left-radius | Radius | 边框左下角的半径。将此属性设置为正值会产生圆角. |
border-style | Border Style | 所有边框边缘的样式. 此属性支持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; } |
border-top-style | Border Style | 边框的顶部边缘的风格. |
border-right-style | Border Style | 边框右边的风格 |
border-bottom-style | Border Style | 边框底边的样式. |
border-left-style | Border Style | 边框左边的样式. |
border-width | Box Lengths | 边框的宽度。相当于设置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-top-width | Length | 边框顶边的宽度 |
border-right-width | Length | 边框右边缘的宽度. |
border-bottom-width | Length | 边框底边的宽度. |
border-left-width | Length | 边框左边缘的宽度. |
bottom | Length | 规定元素的底部边缘。该属性定义了定位元素下外边距边界与其包含块下边界之间的偏移。 如果position是 如果position是 例: QSpinBox::down-button { bottom: 2px } |
button-layout | Number | QDialogButtonBox或QMessageBox中按钮的布局。可能的值为0(WinLayout),1(MacLayout),2(KdeLayout),3(GnomeLayout)和5(AndroidLayout)。 如果未指定此属性,则默认为SH_DialogButtonLayout样式提示的当前样式指定的值 例: * { button-layout: 2 } |
color | Brush | 用于渲染文本的颜色。 所有遵循QWidget :: palette的的控件都支持此属性。 如果未设置此属性,则默认值为QWidget :: foregroundRole(通常为黑色)的窗口小部件调板中设置的内容 例: QPushButton { color: red } |
dialogbuttonbox-buttons-have-icons | Boolean | QDialogButtonBox中的按钮是否显示图标 如果此属性设置为1,则QDialogButtonBox的按钮会显示图标; 如果设置为0,则不显示图标 QDialogButtonBox { dialogbuttonbox-buttons-have-icons: 1; } 注意:必须在创建QDialogButtonBox之前应用定义此属性的样式; 这意味着您必须将样式应用于父窗口小部件或应用程序本身。 |
font | Font | 用于设置文本字体的简写表示法。相当于指定font-family ,font-size ,font-style ,和/或font-weight 。 所有尊循QWidget :: font的小部件都支持此属性。 如果未设置此属性,则默认为QWidget :: font 例: QCheckBox { font: bold italic large "Times New Roman" } |
font-family | String | 字体系列. 例: QCheckBox { font-family: "New Century Schoolbook" } |
font-size | Font Size | 字体大小。在此版本的Qt中,仅支持pt和px指标. 例: QTextEdit { font-size: 12px } |
font-style | Font Style | 字体样式. 例: QTextEdit { font-style: italic } |
font-weight | Font Weight | 字体粗细 |
gridline-color * | Color | QTableView中网格线的颜色。 如果未指定此属性,则默认为SH_Table_GridLineColor样式提示的当前样式指定的值 例: * { gridline-color: gray } |
height | Length | 子控件的高度(或在某些情况下,小部件)。 如果未指定此属性,则默认值取决于子控件/窗口小部件和当前样式。 警告:除非另有说明,否则在小部件上设置此属性时无效。如果您想要一个具有固定高度的小部件,请将min-height和max-height设置为相同的值 例: QSpinBox::down-button { height: 10px } |
icon-size | Length | 窗口小部件中图标的宽度和高度。 可以使用此属性设置QCheckBox、QListView、QPushButton、QRadioButton、QTabBar、QToolBar、QToolBox、QTreeView的图标大小
|
image * | Url+ | 在子控件的内容矩形中绘制的图像。 image属性接受Url的列表或 在子控件上设置图像属性会隐式设置子控件的宽度和高度(除非SVG中的图像)。 在Qt 4.3及更高版本中,可以使用图像位置指定矩形内图像的对齐。 此属性仅用于子控件 - 我们不支持其他元素。 警告:本QIcon需要SVG插件来渲染SVG图像 例: // implicitly sets the size of down-button to the // size of spindown.png QSpinBox::down-button { image: url(:/images/spindown.png) } |
image-position | alignment | 在Qt 4.3及更高版本中,可以使用相对或绝对位置指定图像图像位置的对齐. |
left | Length | 如果position是relative (默认值),则将子控件向右移动一定的偏移量。 如果position是 如果未指定此属性,则默认为 例: QSpinBox::down-button { left: 2px } |
lineedit-password-character* | Number | 该QLineEdit的密码字符作为Unicode数字。 如果未指定此属性,则默认为SH_LineEdit_PasswordCharacter样式提示的当前样式指定的值。 例: * { lineedit-password-character: 9679 } |
lineedit-password-mask-delay* | Number | 将lineedit-password-character应用于可见字符之前的QLineEdit密码掩码延迟(以毫秒为单位)。 如果未指定此属性,则默认为SH_LineEdit_PasswordMaskDelay样式提示的当前样式指定的值。 此属性已添加到Qt 5.4中。 例: * { lineedit-password-mask-delay: 1000 } |
margin | Box Lengths | widget的边距。等效于声明margin-top ,margin-right ,margin-bottom ,和margin-left 。 此属性支持QAbstractItemView中的子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,QTextEdit和QToolTip。 如果未指定此属性,则默认为 例: QLineEdit { margin: 2px } |
margin-top | Length | 部件的上边距. |
margin-right | Length | 部件的右边距. |
margin-bottom | Length | 部件的底部边距. |
margin-left | Length | 部件的左边距. |
max-height | Length | 部件或子控件的最大高度。 此属性支持QAbstractItemView中的子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSizeGrip,QSpinBox,QSplitter,QStatusBar,的QTextEdit和QToolTip。 例: QSpinBox { max-height: 24px } |
max-width | Length | 部件或子控件的最大宽度。 此属性支持QAbstractItemView中的子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSizeGrip,QSpinBox,QSplitter,QStatusBar,的QTextEdit和QToolTip. 例: QComboBox { max-width: 72px } |
messagebox-text-interaction-flags* | Number | 消息框中文本的交互行为。可能的值基于Qt :: TextInteractionFlags。 如果未指定此属性,则默认为SH_MessageBox_TextInteractionFlags样式提示的当前样式指定的值。 例: QMessageBox { messagebox-text-interaction-flags: 5 } |
min-height | Length | 小部件或子控件的最小高度。 此属性支持QAbstractItemView中的子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSizeGrip,QSpinBox,QSplitter,QStatusBar,的QTextEdit和QToolTip。 如果未指定此属性,则根据窗口小部件的内容和样式派生最小高度。 例: QComboBox { min-height: 24px } |
min-width | Length | 小部件或子控件的最小宽度。 此属性支持QAbstractItemView中的子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSizeGrip,QSpinBox,QSplitter,QStatusBar,QTextEdit和QToolTip。 如果未指定此属性,则根据窗口小部件的内容和样式派生最小宽度。 例: QComboBox { min-width: 72px } |
opacity* | Number | 小部件的不透明度。可能的值从0(透明)到255(不透明)。目前,仅支持 tooltips。 如果未指定此属性,则默认为SH_ToolTipLabel_Opacity样式提示的当前样式指定的值。 例: QToolTip { opacity: 223 } |
outline | 围绕对象边框绘制的轮廓. | |
outline-color | Color | 轮廓的颜色。另见 border-color |
outline-offset | Length | 轮廓与窗口小部件边框的偏移量. |
outline-style | 指定用于绘制轮廓的图案。另见 border-style | |
outline-radius | 在轮廓上添加圆角 | |
outline-bottom-left-radius | Radius | 轮廓左下角的半径. |
outline-bottom-right-radius | Radius | 轮廓右下角的半径. |
outline-top-left-radius | Radius | 轮廓左上角的半径. |
outline-top-right-radius | Radius | 轮廓右上角的半径. |
padding | Box Lengths | 部件的填充。等效于声明padding-top ,padding-right ,padding-bottom ,和padding-left 。 此属性支持QAbstractItemView中的子类,QAbstractSpinBox子类,QCheckBox,QComboBox,QFrame,QGroupBox,QLabel,QLineEdit,QMenu,QMenuBar,QPushButton,QRadioButton,QSplitter,的QTextEdit和QToolTip。 如果未指定此属性,则默认为 例: QLineEdit { padding: 3px } |
padding-top | Length | 部件的顶部填充. |
padding-right | Length | 部件的右侧填充. |
padding-bottom | Length | 部件的底部填充. |
padding-left | Length | 部件的左侧填充. |
paint-alternating-row-colors-for-empty-area | bool | QTreeView是否为空白区域(即没有项目的区域)绘制交替的行颜色 |
position | relative | absolute | 使用left,right,top和bottom指定的偏移是相对坐标还是绝对坐标。 如果未指定此属性,则默认为 |
right | Length | 如果position是relative (默认值),则将子控件向左移动一定的偏移量; right: x 相当于left: -x 如果position是 例: QSpinBox::down-button { right: 2px } |
selection-background-color* | Brush | 选定文本或项目的背景。 所有遵循QWidget :: palette并显示选择文本的小部件都支持此属性。 如果未设置此属性,则默认值为为调色板的Highlight角色设置的值。 例: QTextEdit { selection-background-color: darkblue } |
selection-color* | Brush | 所选文本或项目的前景。 所有遵循QWidget :: palette并显示选择文本的小部件都支持此属性。 如果未设置此属性,则默认值为为调色板的HighlightedText角色设置的值。 例: QTextEdit { selection-color: white } |
show-decoration-selected* | Boolean | 控制QListView中的选择是覆盖整行还是仅覆盖文本的范围。 如果未指定此属性,则默认为SH_ItemView_ShowDecorationSelected样式提示的当前样式指定的值。 例: * { show-decoration-selected: 1 } |
spacing* | Length | 小部件中的内部间距。 QCheckBox,可检查的QGroupBox es,QMenuBar和QRadioButton支持此属性。 如果未指定此属性,则默认值取决于窗口小部件和当前样式. 例: QMenuBar { spacing: 10 } |
subcontrol-origin* | Origin | 父元素中子控件的原始矩形。 如果未指定此属性,则默认为 例: QSpinBox::up-button { image: url(:/images/spinup.png); subcontrol-origin: content; subcontrol-position: right top; } |
subcontrol-position* | Alignment | subcontrol-origin指定的原始矩形内的子控件的对齐方式。 如果未指定此属性,则默认为取决于子控件的值。 例: QSpinBox::down-button { image: url(:/images/spindown.png); subcontrol-origin: padding; subcontrol-position: right bottom; } |
titlebar-show-tooltips-on-buttons } | bool | 是否在窗口标题栏按钮上显示工具提示. |
widget-animation-duration* | Number | 动画应该持续多少(以毫秒为单位)。值等于零意味着将禁用动画。 如果未指定此属性,则默认为SH_Widget_Animation_Duration样式提示的当前样式指定的值。 此属性已添加到Qt 5.10中。 例: * { widget-animation-duration: 100 } |
text-align | Alignment | 窗口小部件内容中文本和图标的对齐方式。 如果未指定此值,则默认为取决于本机样式的值。 例: QPushButton { text-align: left; } |
text-decoration | none underline overline line-through | 附加文字效果 |
top | Length | 如果position是relative (默认值),则将子控件向下移动一定的偏移量。 如果position为 如果未指定此属性,则默认为 例: QSpinBox::up-button { top: 2px } |
width | Length | 控件的宽度(或某些情况下的小部件)。 如果未指定此属性,则默认值取决于子控件/窗口小部件和当前样式。 警告:除非另有说明,否则在小部件上设置此属性时无效。如果需要具有固定宽度的窗口小部件,请将min-width和max-width设置为相同的值。 例: QSpinBox::up-button { width: 12px } |