天天看點

Qt Style Sheets ReferenceQt Style Sheets Reference

<a></a>

Qt Style Sheets support various properties, pseudo-states, and subcontrols that make it possible to customize the look of widgets.

The following table lists the Qt widgets that can be customized using style sheets:

Widget

How to Style

Supports styling of the title bar and the title bar buttons when docked.

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

Supports styling of the separator

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.

Overlapping tabs for the selected state are created by using negative margins or using the<code>absolute</code> position scheme.

Warning:

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 above code is a no-operation if there is no stylesheet set.

Property

Type

Description

Example:

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#background">Background</a>

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

The background color used for the widget.

Examples:

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#url">Url</a>

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

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#repeat">Repeat</a>

Whether and how the background image is repeated to fill the <code>background-origin</code>rectangle.

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

<code>background-position</code>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#alignment">Alignment</a>

The alignment of the background image within the <code>background-origin</code> rectangle.

If this property is not specified, the alignment is<code>top</code> <code>left</code>.

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#attachment">Attachment</a>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#origin">Origin</a>

The widget's rectangle, in which the<code>background</code> is drawn.

This property specifies the rectangle to which the <code>background-color</code> and <code>background-image</code>are clipped.

If this property is not specified, the default is<code>border</code>.

The widget's background rectangle, to use in conjunction with <code>background-position</code> and<code>background-image</code>.

If this property is not specified, the default is<code>padding</code>.

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#border">Border</a>

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

<code>border-top</code>

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

<code>border-right</code>

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

<code>border-bottom</code>

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

<code>border-left</code>

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

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#box-colors">Box Colors</a>

The color of all the border's edges. Equivalent to specifying <code>border-top-color</code>,<code>border-right-color</code>, <code>border-bottom-color</code>, and <code>border-left-color</code>.

<code>border-top-color</code>

The color of the border's top edge.

<code>border-right-color</code>

The color of the border's right edge.

<code>border-bottom-color</code>

The color of the border's bottom edge.

<code>border-left-color</code>

The color of the border's left edge.

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#border-image">Border Image</a>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#radius">Radius</a>

The radius of the border's corners. Equivalent to specifying <code>border-top-left-radius</code>,<code>border-top-right-radius</code>,<code>border-bottom-right-radius</code>, and<code>border-bottom-left-radius</code>.

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

<code>border-top-left-radius</code>

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

<code>border-top-right-radius</code>

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

<code>border-bottom-right-radius</code>

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

<code>border-bottom-left-radius</code>

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

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#border-style">Border Style</a>

The style of all the border's edges.

If this property is not specified, it defaults to<code>none</code>.

<code>border-top-style</code>

The style of the border's top edge.

<code>border-right-style</code>

The style of the border's right edge/

<code>border-bottom-style</code>

The style of the border's bottom edge.

<code>border-left-style</code>

The style of the border's left edge.

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#box-lengths">Box Lengths</a>

The width of the border. Equivalent to setting<code>border-top-width</code>, <code>border-right-width</code>,<code>border-bottom-width</code>, and <code>border-left-width</code>.

<code>border-top-width</code>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#length">Length</a>

The width of the border's top edge.

<code>border-right-width</code>

The width of the border's right edge.

<code>border-bottom-width</code>

The width of the border's bottom edge.

<code>border-left-width</code>

The width of the border's left edge.

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#number">Number</a>

The color used to render text.

<code>dialogbuttonbox-buttons-have-icons</code>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#boolean">Boolean</a>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#font">Font</a>

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

<code>font-family</code>

String

The font family.

<code>font-size</code>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#font-size">Font Size</a>

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

<code>font-style</code>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#font-style">Font Style</a>

The font style.

<code>font-weight</code>

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#font-weight">Font Weight</a>

The weight of the font.

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

The width and height of the icon in a widget.

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

<a href="http://doc.qt.io/qt-5/qcheckbox.html">QCheckBox</a>

<a href="http://doc.qt.io/qt-5/qlistview.html">QListView</a>

<a href="http://doc.qt.io/qt-5/qpushbutton.html">QPushButton</a>

<a href="http://doc.qt.io/qt-5/qradiobutton.html">QRadioButton</a>

<a href="http://doc.qt.io/qt-5/qtabbar.html">QTabBar</a>

<a href="http://doc.qt.io/qt-5/qtoolbar.html">QToolBar</a>

<a href="http://doc.qt.io/qt-5/qtoolbox.html">QToolBox</a>

<a href="http://doc.qt.io/qt-5/qtreeview.html">QTreeView</a>

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

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

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

<a href="http://doc.qt.io/qt-5/stylesheet-reference.html#alignment">alignment</a>

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

If this property is not specified, it defaults to <code>0</code>.

This property was added in Qt 5.4.

The widget's margins. Equivalent to specifying<code>margin-top</code>, <code>margin-right</code>, <code>margin-bottom</code>, and <code>margin-left</code>.

<code>margin-top</code>

The widget's top margin.

<code>margin-right</code>

The widget's right margin.

<code>margin-bottom</code>

The widget's bottom margin.

<code>margin-left</code>

The widget's left margin.

The widget's or a subcontrol's maximum height.

The widget's or a subcontrol's maximum width.

The widget's or a subcontrol's minimum height.

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

The widget's or a subcontrol's minimum width.

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

The widget's padding. Equivalent to specifying<code>padding-top</code>, <code>padding-right</code>,<code>padding-bottom</code>, and <code>padding-left</code>.

<code>padding-top</code>

The widget's top padding.

<code>padding-right</code>

The widget's right padding.

<code>padding-bottom</code>

The widget's bottom padding.

<code>padding-left</code>

The widget's left padding.

<code>bool</code>

<code>relative</code> 

| <code>absolute</code>

If this property is not specified, it defaults to<code>relative</code>.

The background of selected text or items.

The foreground of selected text or items.

Internal spacing in the widget.

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

The origin rectangle of the subcontrol within the parent element.

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

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.

<code>text-decoration</code>

<code>none</code> 

<code>underline</code> 

<code>overline</code> 

<code>line-through</code>

Additional text effects

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

Name

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::StandardPixmap</a>

backward-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_ArrowBack</a>

cd-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DriveCDIcon</a>

computer-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_ComputerIcon</a>

desktop-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DesktopIcon</a>

dialog-apply-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogApplyButton</a>

dialog-cancel-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogCancelButton</a>

dialog-close-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogCloseButton</a>

dialog-discard-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogDiscardButton</a>

dialog-help-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogHelpButton</a>

dialog-no-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogNoButton</a>

dialog-ok-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogOkButton</a>

dialog-open-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogOpenButton</a>

dialog-reset-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogResetButton</a>

dialog-save-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogSaveButton</a>

dialog-yes-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DialogYesButton</a>

directory-closed-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DirClosedIcon</a>

directory-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DirIcon</a>

directory-link-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DirLinkIcon</a>

directory-open-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DirOpenIcon</a>

dockwidget-close-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DockWidgetCloseButton</a>

downarrow-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_ArrowDown</a>

dvd-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DriveDVDIcon</a>

file-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileIcon</a>

file-link-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileLinkIcon</a>

filedialog-contentsview-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileDialogContentsView</a>

filedialog-detailedview-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileDialogDetailedView</a>

filedialog-end-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileDialogEnd</a>

filedialog-infoview-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileDialogInfoView</a>

filedialog-listview-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileDialogListView</a>

filedialog-new-directory-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileDialogNewFolder</a>

filedialog-parent-directory-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileDialogToParent</a>

filedialog-start-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_FileDialogStart</a>

floppy-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DriveFDIcon</a>

forward-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_ArrowForward</a>

harddisk-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DriveHDIcon</a>

home-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DirHomeIcon</a>

leftarrow-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_ArrowLeft</a>

messagebox-critical-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_MessageBoxCritical</a>

messagebox-information-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_MessageBoxInformation</a>

messagebox-question-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_MessageBoxQuestion</a>

messagebox-warning-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_MessageBoxWarning</a>

network-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_DriveNetIcon</a>

rightarrow-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_ArrowRight</a>

titlebar-contexthelp-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_TitleBarContextHelpButton</a>

titlebar-maximize-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_TitleBarMaxButton</a>

titlebar-menu-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_TitleBarMenuButton</a>

titlebar-minimize-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_TitleBarMinButton</a>

titlebar-normal-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_TitleBarNormalButton</a>

titlebar-shade-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_TitleBarShadeButton</a>

titlebar-unshade-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_TitleBarUnshadeButton</a>

trash-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_TrashIcon</a>

uparrow-icon

<a href="http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum">QStyle::SP_ArrowUp</a>

The following table summarizes the syntax and meaning of the different property types.

Syntax

{ <code>top</code> 

| <code>bottom</code> 

| <code>left</code> 

| <code>right</code> 

| <code>center</code> }*

Horizontal and/or vertical alignment.

{ <code>scroll</code> 

| <code>fixed</code> }*

Scroll or fixed attachment.

0 | 1

True (<code>1</code>) or false (<code>0</code>).

Shorthand border property.

(<code>stretch</code> | <code>repeat</code>){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.

<code>dashed</code> 

| <code>dot-dash</code> 

| <code>dot-dot-dash</code> 

| <code>dotted</code> 

| <code>double</code> 

| <code>groove</code> 

| <code>inset</code> 

| <code>outset</code> 

| <code>ridge</code> 

| <code>solid</code> 

| <code>none</code>

Specifies a Color or a Gradient or an entry in the Palette.

<code>rgb(r, g, b)</code> 

| <code>rgba(r, g, b, a)</code> 

| <code>hsv(h, s, v)</code> 

| <code>hsva(h, s, v, a)</code> 

| <code>#rrggbb</code> 

Specifies a color as RGB (red, green, blue) or RGBA (red, green, blue, alpha) or HSV (hue, saturation, value) or HSVA (hue, saturation, value, alpha) or a named color. The <code>rgb()</code> or <code>rgba()</code> syntax can be used with integer values between 0 and 255, or with percentages. The value of s, v, and a in <code>hsv()</code> or<code>hsva()</code> must all be in the range 0-255; the value of h must be in the range 0-359.

Shorthand font property.

The size of a font.

<code>normal</code> 

| <code>italic</code> 

| <code>oblique</code>

The style of a font.

| <code>bold</code> 

| <code>100</code> 

| <code>200</code> 

... 

| <code>900</code>

The weight of a font.

<code>qlineargradient</code> 

| <code>qradialgradient</code> 

| <code>qconicalgradient</code>

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.

<code>px</code>: pixels

<code>pt</code>: the size of one point (i.e., 1/72 of an inch)

<code>em</code>: the em width of the font (i.e., the width of 'M')

<code>ex</code>: the ex width of the font (i.e., the height of 'x')

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

A decimal integer or a real number

Examples: <code>0</code>, <code>18</code>, <code>+127</code>, <code>-255</code>, <code>12.34</code>, <code>-.5</code>, <code>0009</code>.

<code>margin</code> 

| <code>border</code> 

| <code>padding</code> 

| <code>content</code>

Indicates which of four rectangles to use.

<code>margin</code>: The margin rectangle. The margin falls outside the border.

<code>border</code>: The border rectangle. This is where any border is drawn.

<code>padding</code>: The padding rectangle. Unlike the margins, padding is located inside the border.

<code>content</code>: The content rectangle. This specifies where the actual contents go, excluding any padding, border, or margin.

<code>alternate-base</code> 

| <code>base</code> 

| <code>bright-text</code> 

| <code>button</code> 

| <code>button-text</code> 

| <code>dark</code> 

| <code>highlight</code> 

| <code>highlighted-text</code> 

| <code>light</code> 

| <code>link</code> 

| <code>link-visited</code> 

| <code>mid</code> 

| <code>midlight</code> 

| <code>shadow</code> 

| <code>text</code> 

| <code>window</code> 

| <code>window-text</code> 

For example,

<code>repeat-x</code> 

| <code>repeat-y</code> 

| <code>repeat</code> 

| <code>no-repeat</code>

A value indicating the nature of repetition.

<code>repeat-x</code>: Repeat horizontally.

<code>repeat-y</code>: Repeat vertically.

<code>repeat</code>: Repeat horizontally and vertically.

<code>no-repeat</code>: Don't repeat.

<code>url(filename)</code>

The following pseudo-states are supported:

Pseudo-State

This state is set when the widget resides in an active window.

The item has horizontal orientation

The mouse is hovering over the item.

For items that can be toggled, this applies to items in the "off" state.

For items that can be toggled, this applies to widgets in the "on" state.

The item is being pressed using the mouse.

The item has vertical orientation.

The widget is a window (i.e top level widget)

The following subcontrols are available:

Sub-Control

本文轉自羅兵部落格園部落格,原文連結:http://www.cnblogs.com/hhh5460/p/4268591.html,如需轉載請自行聯系原作者

繼續閱讀