1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
7 \brief How to use style sheets to customize the appearance of widgets.
9 \ingroup frameworks-technologies
10 \ingroup qt-basic-concepts
11 \ingroup qt-gui-concepts
13 \previouspage {Styles and Style Aware Widgets}{Styles}
14 \nextpage The Style Sheet Syntax
19 Qt Style Sheets are a powerful mechanism that allows you to
20 customize the appearance of widgets, in addition to what is
21 already possible by subclassing QStyle. The concepts,
22 terminology, and syntax of Qt Style Sheets are heavily inspired
23 by HTML \l{http://www.w3.org/Style/CSS/}{Cascading Style Sheets
24 (CSS)} but adapted to the world of widgets.
30 \li \l{The Style Sheet Syntax}
31 \li \l{Qt Designer Integration}
32 \li \l{Customizing Qt Widgets Using Style Sheets}
33 \li \l{Qt Style Sheets Reference}
34 \li \l{Qt Style Sheets Examples}
37 \note If Qt Style Sheets are used on the same widget as functions that
38 set the appearance of widgets, such as \l QWidget::setFont() or
39 \l QTreeWidgetItem::setBackground(), style sheets will take precedence
40 if the settings conflict.
45 Styles sheets are textual specifications that can be set on the
46 whole application using QApplication::setStyleSheet() or on a
47 specific widget (and its children) using
48 QWidget::setStyleSheet(). If several style sheets are set at
49 different levels, Qt derives the effective style sheet from all
50 of those that are set. This is called cascading.
52 For example, the following style sheet specifies that all
53 \l{QLineEdit}s should use yellow as their background color, and
54 all \l{QCheckBox}es should use red as the text color:
56 \snippet code/doc_src_stylesheet.qdoc 0
58 For this kind of customization, style sheets are much more
59 powerful than QPalette. For example, it might be tempting to set
60 the QPalette::Button role to red for a QPushButton to obtain a
61 red push button. However, this wasn't guaranteed to work for all
62 styles, because style authors are restricted by the different
63 platforms' guidelines and (on Windows and \macos) by the
66 Style sheets let you perform all kinds of customizations that are
67 difficult or impossible to perform using QPalette alone. If you
68 want yellow backgrounds for mandatory fields, red text for
69 potentially destructive push buttons, or fancy check boxes, style
70 sheets are the answer.
72 Style sheets are applied on top of the current \l{QStyle}{widget
73 style}, meaning that your applications will look as native as
74 possible, but any style sheet constraints will be taken into
75 consideration. Unlike palette fiddling, style sheets offer
76 guarantees: If you set the background color of a QPushButton to be
77 red, you can be assured that the button will have a red background
78 in all styles, on all platforms. In addition, Qt Designer
79 provides style sheet integration, making it easy to view the effects
80 of a style sheet in different \l{QStyle}{widget styles}.
82 In addition, style sheets can be used to provide a distinctive
83 look and feel for your application, without having to subclass
84 QStyle. For example, you can specify arbitrary images for radio
85 buttons and check boxes to make them stand out. Using this
86 technique, you can also achieve minor customizations that would
87 normally require subclassing several style classes, such as
88 specifying a \l{QStyle::styleHint()}{style hint}.
90 When a style sheet is active, the QStyle returned by QWidget::style()
91 is a wrapper "style sheet" style, \e not the platform-specific style. The
92 wrapper style ensures that any active style sheet is respected and
93 otherwise forwards the drawing operations to the underlying,
94 platform-specific style (e.g., QWindowsVistaStyle on Windows).
96 Since Qt 4.5, Qt style sheets fully supports \macos.
101 \page stylesheet-syntax.html
102 \previouspage Qt Style Sheets
103 \nextpage Qt Designer Integration
104 \title The Style Sheet Syntax
106 Qt Style Sheet terminology and syntactic rules are almost
107 identical to those of HTML CSS. If you already know CSS, you can
108 probably skim quickly through this section.
112 \section1 Style Rules
114 Style sheets consist of a sequence of style rules. A \e{style
115 rule} is made up of a selector and a declaration. The
116 \e{selector} specifies which widgets are affected by the rule;
117 the \e{declaration} specifies which properties should be set on
118 the widget. For example:
120 \snippet code/doc_src_stylesheet.qdoc 1
122 In the above style rule, \c QPushButton is the selector and \c{{
123 color: red }} is the declaration. The rule specifies that
124 QPushButton and its subclasses (e.g., \c MyPushButton) should use
125 red as their foreground color.
127 Qt Style Sheet is generally case insensitive (i.e., \c color,
128 \c Color, \c COLOR, and \c cOloR refer to the same property).
129 The only exceptions are class names,
130 \l{QObject::setObjectName()}{object names}, and Qt property
131 names, which are case sensitive.
133 Several selectors can be specified for the same declaration,
134 using commas (\c{,}) to separate the selectors. For example,
137 \snippet code/doc_src_stylesheet.qdoc 2
139 is equivalent to this sequence of three rules:
141 \snippet code/doc_src_stylesheet.qdoc 3
143 The declaration part of a style rule is a list of
144 \tt{\e{property}: \e{value}} pairs, enclosed in braces (\c{{}})
145 and separated with semicolons. For example:
147 \snippet code/doc_src_stylesheet.qdoc 4
149 See the \l{List of Properties} section below for the list of
150 properties provided by Qt widgets.
152 \section1 Selector Types
154 All the examples so far used the simplest type of selector, the
155 Type Selector. Qt Style Sheets support all the
156 \l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{selectors
157 defined in CSS2}. The table below summarizes the most useful
167 \li Universal Selector
169 \li Matches all widgets.
174 \li Matches instances of QPushButton and of its subclasses.
177 \li Property Selector
178 \li \c{QPushButton[flat="false"]}
179 \li Matches instances of QPushButton that are not
180 \l{QPushButton::}{flat}. You may use this selector to test
181 for any Qt \l{Qt's Property System}{property} that supports
182 QVariant::toString() (see the \l{QVariant::}{toString()}
183 function documentation for details). In addition, the
184 special \c class property is supported, for the name of the
187 This selector may also be used to test dynamic properties.
188 For more information on customization using dynamic properties,
189 refer to \l{Customizing Using Dynamic Properties}.
191 Instead of \c =, you can also use \c ~= to test whether a
192 Qt property of type QStringList contains a given QString.
194 \warning If the value of the Qt property changes after the
195 style sheet has been set, it might be necessary to force a
196 style sheet recomputation. One way to achieve this is to
197 unset the style sheet and set it again.
202 \li Matches instances of QPushButton, but not of its subclasses.
204 This is equivalent to \c{*[class~="QPushButton"]}.
207 \li ID \target ID Selector
209 \li \c{QPushButton#okButton}
210 \li Matches all QPushButton instances whose
211 \l{QObject::objectName}{object name} is \c okButton.
214 \li Descendant Selector
215 \li \c{QDialog QPushButton}
216 \li Matches all instances of QPushButton that are descendants
217 (children, grandchildren, etc.) of a QDialog.
221 \li \c{QDialog > QPushButton}
222 \li Matches all instances of QPushButton that are direct
223 children of a QDialog.
226 \section1 Sub-Controls
228 For styling complex widgets, it is necessary to access subcontrols of the
229 widget, such as the drop-down button of a QComboBox or the up and down
230 arrows of a QSpinBox. Selectors may contain \e{subcontrols} that make it
231 possible to restrict the application of a rule to specific widget
232 subcontrols. For example:
234 \snippet code/doc_src_stylesheet.qdoc 5
236 The above rule styles the drop-down button of all \l{QComboBox}es.
237 Although the double-colon (\c{::}) syntax is reminiscent of CSS3
238 Pseudo-Elements, Qt Sub-Controls differ conceptually from these and have
239 different cascading semantics.
241 Sub-controls are always positioned with respect to another element - a
242 reference element. This reference element could be the widget or another
243 Sub-control. For example, the \l{Qt Style Sheets Reference#drop-down-sub}
244 {::drop-down} of a QComboBox is placed, by default, in the top right corner
245 of the Padding rectangle of the QComboBox. The
246 \l{Qt Style Sheets Reference#drop-down-sub}{::drop-down} is placed,
247 by default, in the Center of the Contents rectangle of the
248 \l{Qt Style Sheets Reference#drop-down-sub}{::drop-down} Sub-control. See
249 the \l{List of Stylable Widgets} below for the Sub-controls to use to
250 style a widget and their default positions.
252 The origin rectangle to be used can be changed using the
253 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}
254 property. For example, if we want to place the drop-down in the margin
255 rectangle of the QComboBox instead of the default Padding rectangle, we
258 \snippet code/doc_src_stylesheet.qdoc 6
260 The alignment of the drop-down within the Margin rectangle is changed
261 using \l{Qt Style Sheets Reference#subcontrol-position-prop}
262 {subcontrol-position} property.
264 The \l{Qt Style Sheets Reference#width-prop}{width} and
265 \l{Qt Style Sheets Reference#height-prop}{height} properties can be used
266 to control the size of the Sub-control. Note that setting a
267 \l{Qt Style Sheets Reference#image-prop}{image} implicitly sets the size
270 The relative positioning scheme
271 (\l{Qt Style Sheets Reference#position-prop}{position} : relative),
272 allows the position of the Sub-Control to be offset from its initial
273 position. For example, when the QComboBox's drop-down button is
274 pressed, we might like the arrow inside to be offset to give a
275 "pressed" effect. To achieve this, we can specify:
277 \snippet code/doc_src_stylesheet.qdoc 7
279 The absolute positioning scheme
280 (\l{Qt Style Sheets Reference#position-prop}{position} : absolute),
281 allows the position and size of the Sub-control to be changed with
282 respect to the reference element.
284 Once positioned, they are treated the same as widgets and can be styled
285 using the \l{box model}.
287 See the \l{List of Sub-Controls} below for a list of supported
288 sub-controls, and \l{Customizing the QPushButton's Menu Indicator
289 Sub-Control} for a realistic example.
291 \note With complex widgets such as QComboBox and QScrollBar, if one
292 property or sub-control is customized, \b{all} the other properties or
293 sub-controls must be customized as well.
295 \section1 Pseudo-States
297 Selectors may contain \e{pseudo-states} that denote that restrict
298 the application of the rule based on the widget's state.
299 Pseudo-states appear at the end of the selector, with a colon
300 (\c{:}) in between. For example, the following rule applies when
301 the mouse hovers over a QPushButton:
303 \snippet code/doc_src_stylesheet.qdoc 8
305 Pseudo-states can be negated using the exclamation operator. For
306 example, the following rule applies when the mouse does not hover
309 \snippet code/doc_src_stylesheet.qdoc 9
311 Pseudo-states can be chained, in which case a logical AND is
312 implied. For example, the following rule applies to when the
313 mouse hovers over a checked QCheckBox:
315 \snippet code/doc_src_stylesheet.qdoc 10
317 Negated Pseudo-states may appear in Pseudo-state chains. For example,
318 the following rule applies when the mouse hovers over a QPushButton
321 \snippet code/doc_src_stylesheet.qdoc 11
323 If needed, logical OR can be expressed using the comma operator:
325 \snippet code/doc_src_stylesheet.qdoc 12
327 Pseudo-states can appear in combination with subcontrols. For
330 \snippet code/doc_src_stylesheet.qdoc 13
332 See the \l{List of Pseudo-States} section below for the list of
333 pseudo-states provided by Qt widgets.
335 \section1 Conflict Resolution
337 Conflicts arise when several style rules specify the same
338 properties with different values. Consider the following style
341 \snippet code/doc_src_stylesheet.qdoc 14
343 Both rules match QPushButton instances called \c okButton and
344 there is a conflict for the \c color property. To resolve this
345 conflict, we must take into account the \e specificity of the
346 selectors. In the above example, \c{QPushButton#okButton} is
347 considered more specific than \c QPushButton, because it
348 (usually) refers to a single object, not to all instances of a
351 Similarly, selectors with pseudo-states are more specific than
352 ones that do not specify pseudo-states. Thus, the following style
353 sheet specifies that a \l{QPushButton} should have white text
354 when the mouse is hovering over it, otherwise red text:
356 \snippet code/doc_src_stylesheet.qdoc 15
360 \snippet code/doc_src_stylesheet.qdoc 16
362 Here, both selectors have the same specificity, so if the mouse
363 hovers over the button while it is enabled, the second rule takes
364 precedence. If we want the text to be white in that case, we can
365 reorder the rules like this:
367 \snippet code/doc_src_stylesheet.qdoc 17
369 Alternatively, we can make the first rule more specific:
371 \snippet code/doc_src_stylesheet.qdoc 18
373 A similar issue arises in conjunction with Type Selectors.
374 Consider the following example:
376 \snippet code/doc_src_stylesheet.qdoc 19
378 Both rules apply to QPushButton instances (since QPushButton
379 inherits QAbstractButton) and there is a conflict for the
380 \l{Qt Style Sheets Reference#color-prop}{color} property. Because QPushButton
381 inherits QAbstractButton, it might be tempting to assume that
382 \c QPushButton is more specific than \c QAbstractButton. However,
383 for style sheet computations, all Type Selectors have the same
384 specificity, and the rule that appears last takes precedence. In
385 other words, \l{Qt Style Sheets Reference#color-prop}{color} is set to \c gray
386 for all \l{QAbstractButton}s, including \l{QPushButton}s. If we really
387 want \l{QPushButton}s to have red text, we can always reorder the
390 For determining the specificity of a rule, Qt Style Sheets follow
392 \l{http://www.w3.org/TR/REC-CSS2/cascade.html#specificity}{CSS2
396 \e{A selector's specificity is calculated as follows:}
399 \li \e{count the number of ID attributes in the selector (= a)}
400 \li \e{count the number of other attributes and pseudo-classes in the selector (= b)}
401 \li \e{count the number of element names in the selector (= c)}
402 \li \e{ignore pseudo-elements [i.e., \l{subcontrols}].}
405 \e{Concatenating the three numbers a-b-c (in a number system with a
406 large base) gives the specificity.}
410 \snippet code/doc_src_stylesheet.qdoc 20
415 Style sheets can be set on the QApplication, on parent widgets,
416 and on child widgets. An arbitrary widget's effective style sheet
417 is obtained by merging the style sheets set on the widget's
418 ancestors (parent, grandparent, etc.), as well as any style sheet
419 set on the QApplication.
421 When conflicts arise, the widget's own style sheet is always
422 preferred to any inherited style sheet, irrespective of the
423 specificity of the conflicting rules. Likewise, the parent
424 widget's style sheet is preferred to the grandparent's, etc.
426 One consequence of this is that setting a style rule on a widget
427 automatically gives it precedence over other rules specified in
428 the ancestor widgets' style sheets or the QApplication style
429 sheet. Consider the following example. First, we set a style
430 sheet on the QApplication:
432 \snippet code/doc_src_stylesheet.cpp 21
434 Then we set a style sheet on a QPushButton object:
436 \snippet code/doc_src_stylesheet.cpp 22
438 The style sheet on the QPushButton forces the QPushButton (and
439 any child widget) to have blue text, in spite of the more
440 specific rule set provided by the application-wide style sheet.
442 The result would have been the same if we had written
444 \snippet code/doc_src_stylesheet.cpp 23
446 except that if the QPushButton had children (which is unlikely),
447 the style sheet would have no impact on them.
449 Style sheet cascading is a complex topic. Refer to the
450 \l{http://www.w3.org/TR/CSS2/cascade.html#cascade}{CSS2
451 Specification} for the gory details. Be aware that Qt currently
452 doesn't implement \c{!important}.
454 \section1 Inheritance
456 In classic CSS, when font and color of an item is not explicitly set,
457 it gets automatically inherited from the parent. By default, when using
458 Qt Style Sheets, a widget does \b{not} automatically inherit its font
459 and color setting from its parent widget.
461 For example, consider a QPushButton inside a QGroupBox:
463 \snippet code/doc_src_stylesheet.cpp 24
465 The QPushButton does not have an explicit color set. Hence, instead
466 of inheriting color of its parent QGroupBox, it has the system color.
467 If we want to set the color on a QGroupBox and its children,
470 \snippet code/doc_src_stylesheet.cpp 25
472 In contrast, setting a font and palette using QWidget::setFont() and
473 QWidget::setPalette() propagates to child widgets.
475 If you would prefer that the font and palette propagate to child widgets,
476 you can set the Qt::AA_UseStyleSheetPropagationInWidgetStyles flag, like
480 \snippet code/doc_src_stylesheet.cpp 96
482 When the widget-style font and palette propagation is enabled, font and
483 palette changes made through Qt Style Sheets will behave as though the
484 user had manually called the corresponding QWidget::setPalette() and
485 QWidget::setFont() methods on all of the QWidgets targeted by the style
486 sheet. If this would have caused propagation in C++, it will cause
487 propagation in style sheets and vice versa.
489 \section1 Widgets Inside C++ Namespaces
491 The Type Selector can be used to style widgets of a particular type. For
494 \snippet code/doc_src_stylesheet.cpp 26
496 Qt Style Sheet uses QObject::className() of the widget to determine
497 when to apply the Type Selector. When custom widgets are inside namespaces,
498 the QObject::className() returns <namespace>::<classname>. This conflicts
499 with the syntax for \l{Sub-Controls}. To overcome this problem,
500 when using the Type Selector for widgets inside namespaces, we must
501 replace the \c{::} with \c{--}. For example,
503 \snippet code/doc_src_stylesheet.cpp 27
505 \section1 Setting QObject Properties
507 From 4.3 and above, any designable Q_PROPERTY
508 can be set using the qproperty-<property name> syntax.
511 \snippet code/doc_src_stylesheet.qdoc 28
513 If the property references an enum declared with Q_ENUM, you should
514 reference its constants by name, not their numeric value.
516 \note Use the qproperty syntax with care, as it modifies the
517 widget that is being painted. Also, the qproperty syntax is evaluated only
518 once, which is when the widget is polished by the style. This means that any
519 attempt to use them in pseudo-states such as QPushButton:hover, will not work.
523 \page stylesheet-designer.html
524 \previouspage The Style Sheet Syntax
525 \nextpage Customizing Qt Widgets Using Style Sheets
526 \title Qt Designer Integration
528 Qt Designer{Qt Designer} is an excellent tool
529 to preview style sheets. You can right-click on any widget in Designer
530 and select \uicontrol{Change styleSheet...} to set the style sheet.
532 \image designer-stylesheet-options.png
534 In Qt 4.2 and later, Qt Designer also includes a
535 style sheet syntax highlighter and validator. The validator indicates
536 if the syntax is valid or invalid, at the bottom left of the \uicontrol{Edit
539 \image designer-validator-highlighter.png
541 When you click \uicontrol{OK} or \uicontrol{Apply}, Qt Designer will automatically display
542 the widget with its new stylesheet.
544 \image designer-stylesheet-usage.png
548 \page stylesheet-customizing.html
549 \previouspage Qt Designer Integration
550 \nextpage Qt Style Sheets Reference
551 \title Customizing Qt Widgets Using Style Sheets
553 When using style sheets, every widget is treated as a box with four
554 concentric rectangles: the margin rectangle, the border rectangle, the
555 padding rectangle, and the content rectangle. The box model describes
556 this in further detail.
561 \section1 The Box Model
563 The four concentric rectangles appear conceptually as below:
565 \image stylesheet-boxmodel.png
568 \li The margin falls outside the border.
569 \li The border is drawn between the margin and the padding.
570 \li The padding falls inside the border, between the border and
572 \li The content is what is left from the original widget or
573 subcontrol once we have removed the margin, the border, and
577 The \l{Qt Style Sheets Reference#margin-prop}{margin},
578 \l{Qt Style Sheets Reference#border-width-prop}
580 \l{Qt Style Sheets Reference#padding-prop}{padding}
581 properties all default to zero. In that case, all four rectangles
582 (\c margin, \c border, \c padding, and \c content) coincide exactly.
584 You can specify a background for the widget using the
585 \l{Qt Style Sheets Reference#background-image-prop}{background-image}
586 property. By default, the background-image is drawn only for the area
587 inside the border. This can be changed using the
588 \l{Qt Style Sheets Reference#background-clip-prop}{background-clip}
589 property. You can use
590 \l{Qt Style Sheets Reference#background-repeat-prop}{background-repeat}
592 \l{Qt Style Sheets Reference#background-origin-prop}{background-origin}
593 to control the repetition and origin of the background image.
595 A background-image does not scale with the size of the widget. To provide
596 a "skin" or background that scales along with the widget size, one must
598 \l{Qt Style Sheets Reference#border-image-prop}{border-image}. Since the
599 border-image property provides an alternate background, it is not required
600 to specify a background-image when border-image is specified. In the case,
601 when both of them are specified, the border-image draws over the
604 In addition, the \l{Qt Style Sheets Reference#image-prop}{image} property
605 may be used to draw an image over the border-image. The image specified does
606 not tile or stretch and when its size does not match the size of the widget,
607 its alignment is specified using the
608 \l{Qt Style Sheets Reference#image-position-prop}{image-position}
609 property. Unlike background-image and border-image, one may specify a
610 SVG in the image property, in which case the image is scaled automatically
611 according to the widget size.
613 The steps to render a rule are as follows:
615 \li Set clip for entire rendering operation (border-radius)
616 \li Draw the background (background-image)
617 \li Draw the border (border-image, border)
618 \li Draw overlay image (image)
622 \section1 Sub-controls
624 A widget is considered as a hierarchy (tree) of subcontrols drawn on top
625 of each other. For example, the QComboBox draws the drop-down sub-control
626 followed by the down-arrow sub-control. A QComboBox is thus rendered as
629 \li Render the QComboBox { } rule
630 \li Render the QComboBox::drop-down { } rule
631 \li Render the QComboBox::down-arrow { } rule
634 Sub-controls share a parent-child relationship. In the case of QComboBox,
635 the parent of down-arrow is the drop-down and the parent of drop-down is
636 the widget itself. Sub-controls are positioned within their parent using
637 the \l{Qt Style Sheets Reference#subcontrol-position-prop}
638 {subcontrol-position} and
639 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}
642 Once positioned, sub-controls can be styled using the \l{box model}.
644 \note With complex widgets such as QComboBox and QScrollBar, if one
645 property or sub-control is customized, \b{all} the other properties or
646 sub-controls must be customized as well.
651 \page stylesheet-reference.html
652 \previouspage Customizing Qt Widgets Using Style Sheets
653 \nextpage Qt Style Sheets Examples
654 \title Qt Style Sheets Reference
656 Qt Style Sheets support various properties, pseudo-states, and
657 subcontrols that make it possible to customize the look of
662 \section1 List of Stylable Widgets
664 The following table lists the Qt widgets that can be customized
673 \li QAbstractScrollArea \target qabstractscrollarea-widget
674 \li Supports the \l{box model}.
676 All derivatives of QAbstractScrollArea, including QTextEdit,
677 and QAbstractItemView (all item view classes), support
678 scrollable backgrounds using
679 \l{Qt Style Sheets Reference#background-attachment-prop}
680 {background-attachment}. Setting the background-attachment to
681 \c{fixed} provides a background-image that does not scroll with the
682 viewport. Setting the background-attachment to \c{scroll}, scrolls
683 the background-image when the scroll bars move.
685 See \l{Qt Style Sheets Examples#Customizing QAbstractScrollArea}
686 {Customizing QAbstractScrollArea} for an example.
689 \li QCheckBox \target qcheckbox-widget
690 \li Supports the \l{box model}. The check indicator can be
691 styled using the \l{#indicator-sub}{::indicator}
692 subcontrol. By default, the indicator is placed in the Top
693 Left corner of the Contents rectangle of the widget.
695 The \l{#spacing-prop}{spacing} property
696 specifies the spacing between the check indicator and
699 See \l{Qt Style Sheets Examples#Customizing QCheckBox}
700 {Customizing QCheckBox} for an example.
703 \li QColumnView \target qcolumnview-widget
704 \li The grip can be styled be using the \l{image-prop}{image} property.
705 The arrow indicators can by styled using the
706 \l{left-arrow-sub}{::left-arrow} subcontrol and the
707 \l{right-arrow-sub}{::right-arrow} subcontrol.
710 \li QComboBox \target qcombobox-widget
711 \li The frame around the combobox can be styled using the
712 \l{box model}. The drop-down button can be styled using
713 the \l{#drop-down-sub}{::drop-down} subcontrol. By default, the
714 drop-down button is placed in the top right corner of the padding
715 rectangle of the widget. The arrow mark inside the drop-down button
716 can be styled using the \l{#down-arrow-sub}{::down-arrow}
717 subcontrol. By default, the arrow is placed in the center of the
718 contents rectangle of the drop-down subcontrol.
720 The color of the placeholder text can be set using the
721 \l{#placeholder-text-color-prop}{placeholder-text-color} property.
723 See \l{Qt Style Sheets Examples#Customizing QComboBox}{Customizing QComboBox}
727 \li QDateEdit \target qdateedit-widget
728 \li See \l{#qspinbox-widget}{QSpinBox}.
731 \li QDateTimeEdit \target qdatetimeedit-widget
732 \li See \l{#qspinbox-widget}{QSpinBox}.
735 \li QDialog \target qdialog-widget
736 \li Supports only the \l{Qt Style Sheets Reference#background-prop}{background},
737 \l{#background-clip-prop}{background-clip} and
738 \l{#background-origin-prop}{background-origin} properties.
740 \warning Make sure you define the Q_OBJECT macro for your custom
744 \li QDialogButtonBox \target qdialogbuttonbox-widget
745 \li The layout of buttons can be altered using the
746 \l{#button-layout-prop}{button-layout} property.
749 \li QDockWidget \target qdockwidget-widget
750 \li Supports styling of the title bar and the title bar buttons when docked.
752 The dock widget border can be styled using the \l{#border-prop}{border}
753 property. The \l{#title-sub}{::title} subcontrol can be used to customize
754 the title bar. The close and float buttons are positioned with respect
755 to the \l{title-sub}{::title} subcontrol using the
756 \l{#close-button-sub}{::close-button} and
757 \l{#float-button-sub}{::float-button} respectively.
759 When the title bar is vertical, the \l{#vertical-ps}{:vertical} pseudo
760 class is set. In addition, depending on QDockWidget::DockWidgetFeature,
761 the \l{#closable-ps}{:closable}, \l{#floatable-ps}{:floatable} and
762 \l{#movable-ps}{:movable} pseudo states are set.
764 \note Use QMainWindow::separator to style the resize handle.
766 \warning The style sheet has no effect when the QDockWidget is undocked
767 as Qt uses native top level windows when undocked.
769 See \l{Qt Style Sheets Examples#Customizing QDockWidget}
770 {Customizing QDockWidget} for an example.
773 \li QDoubleSpinBox \target qdoublespinbox-widget
774 \li See \l{#qspinbox-widget}{QSpinBox}.
777 \li QFrame \target qframe-widget
778 \li Supports the \l{box model}.
780 Since 4.3, setting a stylesheet on a QLabel automatically
781 sets the QFrame::frameStyle property to QFrame::StyledPanel.
783 See \l{Qt Style Sheets Examples#Customizing QFrame}{Customizing QFrame}
787 \li QGroupBox \target qgroupbox-widget
788 \li Supports the \l{box model}. The title can be styled using the
789 \l{#title-sub}{::title} subcontrol. By default, the title is placed
790 depending on QGroupBox::textAlignment.
792 In the case of a checkable QGroupBox, the title includes the
793 check indicator. The indicator is styled using the
794 \l{#indicator-sub}{::indicator} subcontrol. The
795 \l{#spacing-prop}{spacing} property can be used to control
796 the spacing between the text and indicator.
798 See \l{Qt Style Sheets Examples#Customizing QGroupBox}{Customizing QGroupBox}
802 \li QHeaderView \target qheaderview-widget
803 \li Supports the \l{box model}. The sections of the header view are
804 styled using the \l{#section-sub}{::section} sub control. The
805 \c{section} Sub-control supports the \l{#middle-ps}{:middle},
806 \l{#first-ps}{:first}, \l{#last-ps}{:last},
807 \l{#only-one-ps}{:only-one}, \l{#next-selected-ps}{:next-selected},
808 \l{#previous-selected-ps}{:previous-selected},
809 \l{#selected-ps}{:selected},
810 and \l{#checked-ps}{:checked} pseudo states.
812 The sort indicator can be styled using the
813 \l{#up-arrow-sub}{::up-arrow} and the
814 \l{#down-arrow-sub}{::down-arrow} Sub-control.
816 See \l{Qt Style Sheets Examples#Customizing QHeaderView}{Customizing QHeaderView}
820 \li QLabel \target qlabel-widget
821 \li Supports the \l{box model}. Does not support the
822 \l{#hover-ps}{:hover} pseudo-state.
824 Since 4.3, setting a stylesheet on a QLabel automatically
825 sets the QFrame::frameStyle property to QFrame::StyledPanel.
827 See \l{Qt Style Sheets Examples#Customizing QFrame}{Customizing QFrame} for an
828 example (a QLabel derives from QFrame).
831 \li QLineEdit \target qlineedit-widget
832 \li Supports the \l{box model}.
834 The color and background of the selected item is styled using
835 \l{#selection-color-prop}{selection-color} and
836 \l{#selection-background-color-prop}{selection-background-color}
839 The color of the placeholder text can be set using the
840 \l{#placeholder-text-color-prop}{placeholder-text-color} property.
842 The password character can be styled using the
843 \l{#lineedit-password-character-prop}{lineedit-password-character}
846 The password mask delay can be changed using the
847 \l{#lineedit-password-mask-delay-prop}{lineedit-password-mask-delay}
849 See \l{Qt Style Sheets Examples#Customizing QLineEdit}{Customizing QLineEdit}
853 \li QListView \target qlistview-widget
854 \li Supports the \l{box model}. When
855 \l{QAbstractItemView::alternatingRowColors}{alternating row colors}
856 is enabled, the alternating colors can be styled using the
857 \l{#alternate-background-color-prop}{alternate-background-color}
860 The color and background of the selected item is styled using
861 \l{#selection-color-prop}{selection-color} and
862 \l{#selection-background-color-prop}{selection-background-color}
865 The selection behavior is controlled by the
866 \l{#show-decoration-selected-prop}{show-decoration-selected} property.
868 Use the \l{#item-sub}{::item} subcontrol for more fine grained
869 control over the items in the QListView.
871 See \l{qabstractscrollarea-widget}{QAbsractScrollArea} to
872 style scrollable backgrounds.
874 See \l{Qt Style Sheets Examples#Customizing QListView}
875 {Customzing QListView} for an example.
878 \li QListWidget \target qlistwidget-widget
879 \li See \l{#qlistview-widget}{QListView}.
882 \li QMainWindow \target qmainwindow-widget
883 \li Supports styling of the separator
885 The separator in a QMainWindow when using QDockWidget is styled
886 using the \l{#separator-sub}{::separator} subcontrol.
888 See \l{Qt Style Sheets Examples#Customizing QMainWindow}{Customizing QMainWindow}
892 \li QMenu \target qmenu-widget
893 \li Supports the \l{box model}.
895 Individual items are styled using the \l{#item-sub}{::item}
896 subcontrol. In addition to the usually supported pseudo states,
897 \c{item} subcontrol supports the
898 \l{#selected-ps}{:selected}, \l{#default-ps}{:default},
899 \l{#exclusive-ps}{:exclusive} and the
900 \l{#non-exclusive-ps}{non-exclusive} pseudo states.
902 The indicator of checkable menu items is styled using the
903 \l{#indicator-sub}{::indicator} subcontrol.
905 The separator is styled using the \l{#separator-sub}{::separator}
908 For items with a sub menu, the arrow marks are styled using the
909 \l{right-arrow-sub}{right-arrow} and
910 \l{left-arrow-sub}{left-arrow}.
912 The scroller is styled using the \l{#scroller-sub}{::scroller}.
914 The tear-off is styled using the \l{#tearoff-sub}{::tearoff}.
916 See \l{Qt Style Sheets Examples#Customizing QMenu}{Customizing QMenu}
920 \li QMenuBar \target qmenubar-widget
921 \li Supports the \l{box model}. The \l{#spacing-prop}{spacing}
922 property specifies the spacing between menu items.
923 Individual items are styled using the \l{#item-sub}{::item}
926 \warning When running on Qt/Mac, the menu bar is usually embedded into the
927 system-wide menu bar. In this case, the style sheet will have no effect.
929 See \l{Qt Style Sheets Examples#Customizing QMenuBar}{Customizing QMenuBar}
933 \li QMessageBox \target qmessagebox-widget
934 \li The \l{#messagebox-text-interaction-flags-prop}
935 {messagebox-text-interaction-flags} property can be used to alter
936 the interaction with text in the message box.
939 \li QProgressBar \target qprogressbar-widget
940 \li Supports the \l{box model}. The chunks of the progress bar
941 can be styled using the \l{#chunk-sub}{::chunk} subcontrol.
942 The chunk is displayed on the Contents rectangle of the widget.
944 If the progress bar displays text, use the \l{text-align-prop}{text-align}
945 property to position the text.
947 Indeterminate progress bars have the
948 \l{#indeterminate-ps}{:indeterminate} pseudo state set.
950 See \l{Qt Style Sheets Examples#Customizing QProgressBar}{Customizing QProgressBar}
954 \li QPushButton \target qpushbutton-widget
955 \li Supports the \l{box model}. Supports the \l{#default-ps}{:default},
956 \l{#flat-ps}{:flat}, \l{#checked-ps}{:checked} pseudo states.
958 Since 5.15, the \l{#icon-prop}{icon} property can be set to
959 override the button icon.
961 For QPushButton with a menu, the menu indicator is styled
962 using the \l{#menu-indicator-sub}{::menu-indicator}
963 subcontrol. Appearance of checkable push buttons can be
964 customized using the \l{#open-ps}{:open} and
965 \l{#closed-ps}{:closed} pseudo-states.
967 \warning If you only set a background-color on a QPushButton, the background
968 may not appear unless you set the border property to some value. This is
969 because, by default, the QPushButton draws a native border which completely
970 overlaps the background-color. For example,
972 \snippet code/doc_src_stylesheet.qdoc 30
974 See \l{Qt Style Sheets Examples#Customizing QPushButton}{Customizing QPushButton}
978 \li QRadioButton \target qradiobutton-widget
979 \li Supports the \l{box model}. The check indicator can be
980 styled using the \l{#indicator-sub}{::indicator}
981 subcontrol. By default, the indicator is placed in the Top
982 Left corner of the Contents rectangle of the widget.
984 The \l{#spacing-prop}{spacing} property
985 specifies the spacing between the check indicator and
988 See \l{Qt Style Sheets Examples#Customizing QRadioButton}
989 {Customizing QRadioButton} for an example.
992 \li QScrollBar \target qscrollbar-widget
993 \li Supports the \l{box model}. The Contents rectangle of the widget
994 is considered to be the groove over which the slider moves. The extent
995 of the QScrollBar (i.e the width or the height depending on the orientation)
996 is set using the \l{#width-prop}{width} or \l{#height-prop}{height} property
997 respectively. To determine the orientation, use the
998 \l{#horizontal-ps}{:horizontal} and the \l{vertical-ps}{:vertical}
1001 The slider can be styled using the \l{#handle-sub}{::handle} subcontrol.
1002 Setting the \l{#min-width-prop}{min-width} or \l{#min-height-prop}{min-height}
1003 provides size constraints for the slider depending on the orientation.
1005 The \l{add-line-sub}{::add-line} subcontrol can be used to style the
1006 button to add a line. By default, the add-line subcontrol is placed in
1007 top right corner of the Border rectangle of the widget. Depending on the
1008 orientation the \l{#right-arrow-sub}{::right-arrow} or
1009 \l{#down-arrow-sub}{::down-arrow}. By default, the arrows are placed in
1010 the center of the Contents rectangle of the add-line subcontrol.
1012 The \l{sub-line-sub}{::sub-line} subcontrol can be used to style the
1013 button to subtract a line. By default, the sub-line subcontrol is placed in
1014 bottom right corner of the Border rectangle of the widget. Depending on the
1015 orientation the \l{#left-arrow-sub}{::left-arrow} or
1016 \l{#up-arrow-sub}{::up-arrow}. By default, the arrows are placed in
1017 the center of the Contents rectangle of the sub-line subcontrol.
1019 The \l{sub-page-sub}{::sub-page} subcontrol can be used to style the
1020 region of the slider that subtracts a page. The \l{add-page-sub}{::add-page}
1021 subcontrol can be used to style the region of the slider that adds a page.
1023 See \l{Qt Style Sheets Examples#Customizing QScrollBar}{Customizing QScrollBar}
1027 \li QSizeGrip \target qsizegrip-widget
1028 \li Supports the \l{#width-prop}{width},
1029 \l{#height-prop}{height}, and \l{#image-prop}{image}
1032 See \l{Qt Style Sheets Examples#Customizing QSizeGrip}{Customizing QSizeGrip}
1036 \li QSlider \target qslider-widget
1037 \li Supports the \l{box model}. For horizontal slides, the
1038 \l{min-width-prop}{min-width} and \l{height-prop}{height}
1039 properties must be provided. For vertical sliders, the
1040 \l{min-height-prop}{min-height} and \l{width-prop}{width}
1041 properties must be provided.
1043 The groove of the slider is styled
1044 using the \l{#groove-sub}{::groove}. The groove is
1045 positioned by default in the Contents rectangle of the widget.
1046 The thumb of the slider is styled using \l{#handle-sub}{::handle}
1047 subcontrol. The subcontrol moves in the Contents rectangle of
1048 the groove subcontrol.
1050 See \l{Qt Style Sheets Examples#Customizing QSlider}{Customizing QSlider}
1054 \li QSpinBox \target qspinbox-widget
1055 \li The frame of the spin box can be styled using the \l{box
1058 The up button and arrow can be styled using the
1059 \l{#up-button-sub}{::up-button} and
1060 \l{#up-arrow-sub}{::up-arrow} subcontrols. By default,
1061 the up-button is placed in the top right corner in the
1062 Padding rectangle of the widget. Without an explicit size,
1063 it occupies half the height of its reference rectangle.
1064 The up-arrow is placed in the center of the Contents
1065 rectangle of the up-button.
1067 The down button and arrow can be styled using the
1068 \l{#down-button-sub}{::down-button} and
1069 \l{#down-arrow-sub}{::down-arrow} subcontrols. By default,
1070 the down-button is placed in the bottom right corner in the
1071 Padding rectangle of the widget. Without an explicit size,
1072 it occupies half the height of its reference rectangle.
1073 The bottom-arrow is placed in the center of the Contents
1074 rectangle of the bottom-button.
1076 See \l{Qt Style Sheets Examples#Customizing QSpinBox}{Customizing QSpinBox}
1080 \li QSplitter \target qsplitter-widget
1081 \li Supports the \l{box model}. The handle of the splitter
1082 is styled using the \l{#handle-sub}{::handle} subcontrol.
1084 See \l{Qt Style Sheets Examples#Customizing QSplitter}{Customizing QSplitter}
1088 \li QStatusBar \target qstatusbar-widget
1089 \li Supports only the \l{Qt Style Sheets Reference#background-prop}
1090 {background} property.
1091 The frame for individual items can be style using the
1092 \l{#item-sub}{::item} subcontrol.
1094 See \l{Qt Style Sheets Examples#Customizing QStatusBar}{Customizing QStatusBar}
1098 \li QTabBar \target qtabbar-widget
1099 \li Individual tabs may be styled using the \l{#tab-sub}{::tab} subcontrol.
1100 Close buttons using the \l{#close-button-sub}{::close-button}
1101 The tabs support the
1102 \l{#only-one-ps}{:only-one}, \l{#first-ps}{:first},
1103 \l{#last-ps}{:last}, \l{#middle-ps}{:middle},
1104 \l{#previous-selected-ps}{:previous--selected},
1105 \l{#next-selected-ps}{:next-selected},
1106 \l{#selected-ps}{:selected} pseudo states.
1108 The \l{#top-ps}{:top}, \l{#left-ps}{:left}, \l{#right-ps}{:right},
1109 \l{#bottom-ps}{:bottom} pseudo states depending on the orientation
1112 Overlapping tabs for the selected state are created by using
1113 negative margins or using the \c{absolute} position scheme.
1115 The tear indicator of the QTabBar is styled using the
1116 \l{#tear-sub}{::tear} subcontrol.
1118 QTabBar used two QToolButtons for its scrollers that can be styled
1119 using the \c{QTabBar QToolButton} selector. To specify the width
1120 of the scroll button use the \l{#scroller-sub}{::scroller}
1123 The alignment of the tabs within the QTabBar is styled
1124 using the \l{#Alignment}{alignment} property. \warning
1126 To change the position of the QTabBar within a QTabWidget, use the
1127 \l{#tab-bar-sub}{tab-bar} subcontrol (and set subcontrol-position).
1129 See \l{Qt Style Sheets Examples#Customizing QTabWidget and QTabBar}{Customizing QTabBar}
1133 \li QTabWidget \target qtabwidget-widget
1134 \li The frame of the tab widget is styled using the
1135 \l{#pane-sub}{::pane} subcontrol. The left and right
1136 corners are styled using the \l{#left-corner-sub}{::left-corner}
1137 and \l{#right-corner-sub}{::right-corner} respectively.
1138 The position of the tab bar is controlled using the
1139 \l{#tab-bar-sub}{::tab-bar} subcontrol.
1141 By default, the subcontrols have positions of a QTabWidget in
1142 the QWindowsStyle. To place the QTabBar in the center, set the
1143 subcontrol-position of the tab-bar subcontrol.
1145 The \l{#top-ps}{:top}, \l{#left-ps}{:left}, \l{#right-ps}{:right},
1146 \l{#bottom-ps}{:bottom} pseudo states depending on the orientation
1149 See \l{Qt Style Sheets Examples#Customizing QTabWidget and QTabBar}
1150 {Customizing QTabWidget} for an example.
1153 \li QTableView \target qtableview-widget
1154 \li Supports the \l{box model}. When
1155 \l{QAbstractItemView::alternatingRowColors}{alternating row colors}
1156 is enabled, the alternating colors can be styled using the
1157 \l{#alternate-background-color-prop}{alternate-background-color}
1160 The color and background of the selected item is styled using
1161 \l{#selection-color-prop}{selection-color} and
1162 \l{#selection-background-color-prop}{selection-background-color}
1165 The corner widget in a QTableView is implemented as a QAbstractButton
1166 and can be styled using the "QTableView QTableCornerButton::section"
1169 \warning If you only set a background-color on a QTableCornerButton,
1170 the background may not appear unless you set the border property to
1171 some value. This is because, by default, the QTableCornerButton draws a
1172 native border which completely overlaps the background-color.
1174 The color of the grid can be specified using the
1175 \l{#gridline-color-prop}{gridline-color} property.
1177 See \l{qabstractscrollarea-widget}{QAbsractScrollArea} to
1178 style scrollable backgrounds.
1180 See \l{Qt Style Sheets Examples#Customizing QTableView}
1181 {Customzing QTableView} for an example.
1184 \li QTableWidget \target qtablewidget-widget
1185 \li See \l{#qtableview-widget}{QTableView}.
1188 \li QTextEdit \target qtextedit-widget
1189 \li Supports the \l{box model}.
1191 The color and background of selected text is styled using
1192 \l{#selection-color-prop}{selection-color} and
1193 \l{#selection-background-color-prop}{selection-background-color}
1196 The color of the placeholder text can be set using the
1197 \l{#placeholder-text-color-prop}{placeholder-text-color} property.
1199 See \l{qabstractscrollarea-widget}{QAbsractScrollArea} to
1200 style scrollable backgrounds.
1203 \li QTimeEdit \target qtimeedit-widget
1204 \li See \l{#qspinbox-widget}{QSpinBox}.
1207 \li QToolBar \target qtoolbar-widget
1208 \li Supports the \l{box model}.
1210 The \l{#top-ps}{:top}, \l{#left-ps}{:left}, \l{#right-ps}{:right},
1211 \l{#bottom-ps}{:bottom} pseudo states depending on the area in
1212 which the tool bar is grouped.
1214 The \l{#first-ps}{:first}, \l{#last-ps}{:last}, \l{#middle-ps}{:middle},
1215 \l{#only-one-ps}{:only-one} pseudo states indicator the position
1216 of the tool bar within a line group (See
1217 QStyleOptionToolBar::positionWithinLine).
1219 The separator of a QToolBar is styled using the
1220 \l{#separator-sub}{::separator} subcontrol.
1222 The handle (to move the toolbar) is styled using the
1223 \l{#handle-sub}{::handle} subcontrol.
1225 See \l{Qt Style Sheets Examples#Customizing QToolBar}{Customizing QToolBar}
1229 \li QToolButton \target qtoolbutton-widget
1230 \li Supports the \l{box model}.
1232 If the QToolButton has a menu, is
1233 \l{#menu-indicator-sub}{::menu-indicator} subcontrol can be used to
1234 style the indicator. By default, the menu-indicator is positioned
1235 at the bottom right of the Padding rectangle of the widget.
1237 If the QToolButton is in QToolButton::MenuButtonPopup mode,
1238 the \l{#menu-button-sub}{::menu-button} subcontrol is used to draw the
1239 menu button. \l{#menu-arrow-sub}{::menu-arrow} subcontrol is used to
1240 draw the menu arrow inside the menu-button. By default, it is
1241 positioned in the center of the Contents rectangle of the
1242 menu-button subcontrol.
1244 When the QToolButton displays arrows, the \l{#up-arrow-sub}{::up-arrow},
1245 \l{#down-arrow-sub}{::down-arrow}, \l{#left-arrow-sub}{::left-arrow}
1246 and \l{#right-arrow-sub}{::right-arrow} subcontrols are used.
1248 \warning If you only set a background-color on a QToolButton, the background
1249 will not appear unless you set the border property to some value. This is
1250 because, by default, the QToolButton draws a native border which completely
1251 overlaps the background-color. For example,
1253 \snippet code/doc_src_stylesheet.qdoc 31
1255 See \l{Qt Style Sheets Examples#Customizing QToolButton}{Customizing QToolButton}
1259 \li QToolBox \target qtoolbox-widget
1260 \li Supports the \l{box model}.
1262 The individual tabs can by styled using the
1263 \l{#tab-sub}{::tab} subcontrol. The tabs support the
1264 \l{#only-one-ps}{:only-one}, \l{#first-ps}{:first},
1265 \l{#last-ps}{:last}, \l{#middle-ps}{:middle},
1266 \l{#previous-selected-ps}{:previous-selected},
1267 \l{#next-selected-ps}{:next-selected},
1268 \l{#selected-ps}{:selected} pseudo states.
1271 \li QToolTip \target qtooltip-widget
1272 \li Supports the \l{box model}. The \l{#opacity-prop}{opacity}
1273 property controls the opacity of the tooltip.
1275 See \l{Qt Style Sheets Examples#Customizing QFrame}{Customizing QFrame}
1276 for an example (a QToolTip is a QFrame).
1279 \li QTreeView \target qtreeview-widget
1280 \li Supports the \l{box model}. When
1281 \l{QAbstractItemView::alternatingRowColors}{alternating row colors}
1282 is enabled, the alternating colors can be styled using the
1283 \l{#alternate-background-color-prop}{alternate-background-color}
1286 The color and background of the selected item is styled using
1287 \l{#selection-color-prop}{selection-color} and
1288 \l{#selection-background-color-prop}{selection-background-color}
1291 The selection behavior is controlled by the
1292 \l{#show-decoration-selected-prop}{show-decoration-selected} property.
1294 The branches of the tree view can be styled using the
1295 \l{#branch-sub}{::branch} subcontrol. The
1296 ::branch Sub-control supports the \l{open-ps}{:open},
1297 \l{closed-ps}{:closed}, \l{has-siblings-ps}{:has-sibling} and
1298 \l{has-children-ps}{:has-children} pseudo states.
1300 Use the \l{#item-sub}{::item} subcontrol for more fine grained
1301 control over the items in the QTreeView.
1303 See \l{qabstractscrollarea-widget}{QAbsractScrollArea} to
1304 style scrollable backgrounds.
1306 See \l{Qt Style Sheets Examples#Customizing QTreeView}{Customizing QTreeView}
1307 for an example to style the branches.
1310 \li QTreeWidget \target qtreewidget-widget
1311 \li See \l{#qtreeview-widget}{QTreeView}.
1314 \li QWidget \target qwidget-widget
1315 \li Supports only the \l{Qt Style Sheets Reference#background-prop}{background},
1316 \l{#background-clip-prop}{background-clip} and
1317 \l{#background-origin-prop}{background-origin} properties.
1319 If you subclass from QWidget, you need to provide a paintEvent for your
1320 custom QWidget as below:
1321 \snippet code/doc_src_stylesheet.cpp 32
1323 The above code is a no-operation if there is no stylesheet set.
1325 \warning Make sure you define the Q_OBJECT macro for your custom
1330 \section1 List of Properties
1332 The table below lists all the properties supported by Qt Style
1333 Sheets. Which values can be given to an property depend on the
1334 \l{List of Property Types}{property's type}. Unless otherwise
1335 specified, properties below apply to all widgets. Properties
1336 marked with an asterisk * are specific to Qt and have no equivalent
1346 \li \b{\c accent-color}
1347 \li \l{#Brush}{Brush} \br
1348 \li The property sets the \c AccentColor, which is used to emphasize
1349 interactive UI elements.
1350 If this property is not set, it defaults to the \c highlight color.
1353 \li \b{\c alternate-background-color} \target alternate-background-color-prop
1354 \li \l{#Brush}{Brush} \br
1355 \li The \l{QAbstractItemView::alternatingRowColors}
1356 {alternate background color} used in QAbstractItemView subclasses.
1358 If this property is not set, the default value is
1359 whatever is set for the palette's
1360 \l{QPalette::}{AlternateBase} role.
1364 \snippet code/doc_src_stylesheet.qdoc 33
1366 See also \l{Qt Style Sheets Reference#background-prop}{background} and
1367 \l{#selection-background-color-prop}{selection-background-color}.
1370 \li \b{\c background} \target background-prop
1371 \li \l{#Background}{Background}
1372 \li Shorthand notation for setting the background. Equivalent
1373 to specifying \c background-color, \c background-image, \c
1374 background-repeat, and/or \c background-position.
1376 This property is supported by QAbstractItemView
1377 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1378 QComboBox, QDialog, QFrame, QGroupBox, QLabel, QLineEdit,
1379 QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter,
1380 QTextEdit, QToolTip, and plain \l{QWidget}s.
1384 \snippet code/doc_src_stylesheet.qdoc 34
1387 Often, it is required to set a fill pattern similar to the styles
1388 in Qt::BrushStyle. You can use the background-color property for
1389 Qt::SolidPattern, Qt::RadialGradientPattern, Qt::LinearGradientPattern
1390 and Qt::ConicalGradientPattern. The other patterns are easily achieved
1391 by creating a background image that contains the pattern.
1395 \snippet code/doc_src_stylesheet.qdoc 35
1397 See also \l{#background-origin-prop}{background-origin},
1398 \l{#selection-background-color-prop}{selection-background-color},
1399 \l{#background-clip-prop}{background-clip},
1400 \l{#background-attachment-prop}{background-attachment}
1401 and \l{#alternate-background-color-prop}{alternate-background-color}.
1404 \li \c background-color \target background-color-prop
1405 \li \l{#Brush}{Brush} \br
1406 \li The background color used for the widget.
1410 \snippet code/doc_src_stylesheet.qdoc 36
1413 \li \c background-image \target background-image-prop
1415 \li The background image used for the widget. Semi-transparent
1416 parts of the image let the \c background-color shine
1421 \snippet code/doc_src_stylesheet.qdoc 37
1424 \li \c background-repeat \target background-repeat-prop
1425 \li \l{#Repeat}{Repeat}
1426 \li Whether and how the background image is repeated to fill
1427 the \c background-origin rectangle.
1429 If this property is not specified, the background image
1430 is repeated in both directions (\c repeat).
1434 \snippet code/doc_src_stylesheet.qdoc 38
1437 \li \c background-position
1438 \li \l{#Alignment}{Alignment}
1439 \li The alignment of the background image within the \c
1440 background-origin rectangle.
1442 If this property is not specified, the alignment is \c
1447 \snippet code/doc_src_stylesheet.qdoc 39
1450 \li \b{\c background-attachment} \target background-attachment-prop
1451 \li \l{#Attachment}{Attachment}
1452 \li Determines whether the background-image in a QAbstractScrollArea
1453 is scrolled or fixed with respect to the viewport.
1454 By default, the background-image scrolls with the viewport.
1458 \snippet code/doc_src_stylesheet.qdoc 40
1460 See also \l{Qt Style Sheets Reference#background-prop}{background}
1463 \li \b{\c background-clip} \target background-clip-prop
1464 \li \l{#Origin}{Origin}
1465 \li The widget's rectangle, in which the \c background is drawn.
1467 This property specifies the rectangle to which the \c background-color
1468 and \c background-image are clipped.
1470 This property is supported by QAbstractItemView
1471 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1472 QComboBox, QDialog, QFrame, QGroupBox, QLabel,
1473 QPushButton, QRadioButton, QSplitter, QTextEdit, QToolTip,
1474 and plain \l{QWidget}s.
1476 If this property is not specified, the default is \c
1481 \snippet code/doc_src_stylesheet.qdoc 41
1483 See also \l{Qt Style Sheets Reference#background-prop}{background},
1484 \l{#background-origin-prop}{background-origin} and \l{The Box Model}.
1487 \li \b{\c background-origin} \target background-origin-prop
1488 \li \l{#Origin}{Origin}
1489 \li The widget's background rectangle, to use in conjunction
1490 with \c background-position and \c background-image.
1492 This property is supported by QAbstractItemView
1493 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1494 QComboBox, QDialog, QFrame, QGroupBox, QLabel,
1495 QPushButton, QRadioButton, QSplitter, QTextEdit, QToolTip,
1496 and plain \l{QWidget}s.
1498 If this property is not specified, the default is \c
1503 \snippet code/doc_src_stylesheet.qdoc 42
1505 See also \l{Qt Style Sheets Reference#background-prop}{background} and
1509 \li \b{\c border} \target border-prop
1510 \li \l{#Border}{Border}
1511 \li Shorthand notation for setting the widget's border. Equivalent
1512 to specifying \c border-color, \c border-style, and/or
1515 This property is supported by QAbstractItemView
1516 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1517 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit,
1518 QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter,
1519 QTextEdit, QToolTip, and plain \l{QWidget}s.
1523 \snippet code/doc_src_stylesheet.qdoc 43
1527 \li \l{#Border}{Border}
1528 \li Shorthand notation for setting the widget's top border.
1529 Equivalent to specifying \c border-top-color, \c
1530 border-top-style, and/or \c border-top-width.
1534 \li \l{#Border}{Border}
1535 \li Shorthand notation for setting the widget's right border.
1536 Equivalent to specifying \c border-right-color, \c
1537 border-right-style, and/or \c border-right-width.
1540 \li \c border-bottom
1541 \li \l{#Border}{Border}
1542 \li Shorthand notation for setting the widget's bottom border.
1543 Equivalent to specifying \c border-bottom-color, \c
1544 border-bottom-style, and/or \c border-bottom-width.
1548 \li \l{#Border}{Border}
1549 \li Shorthand notation for setting the widget's left border.
1550 Equivalent to specifying \c border-left-color, \c
1551 border-left-style, and/or \c border-left-width.
1554 \li \b{\c border-color} \target border-attrs
1555 \target border-color-prop
1556 \li \l{#Box Colors}{Box Colors}
1557 \li The color of all the border's edges. Equivalent to
1558 specifying \c border-top-color, \c border-right-color, \c
1559 border-bottom-color, and \c border-left-color.
1561 This property is supported by QAbstractItemView
1562 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1563 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit,
1564 QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter,
1565 QTextEdit, QToolTip, and plain \l{QWidget}s.
1567 If this property is not specified, it defaults to
1568 \l{#color-prop}{color} (i.e., the widget's foreground
1573 \snippet code/doc_src_stylesheet.qdoc 44
1575 See also \l{Qt Style Sheets Reference#border-style-prop}{border-style},
1576 \l{Qt Style Sheets Reference#border-width-prop}{border-width},
1577 \l{#border-image-prop}{border-image}, and \l{The Box Model}.
1580 \li \c border-top-color
1581 \li \l{#Brush}{Brush} \br
1582 \li The color of the border's top edge.
1585 \li \c border-right-color
1586 \li \l{#Brush}{Brush} \br
1587 \li The color of the border's right edge.
1590 \li \c border-bottom-color
1591 \li \l{#Brush}{Brush} \br
1592 \li The color of the border's bottom edge.
1595 \li \c border-left-color
1596 \li \l{#Brush}{Brush} \br
1597 \li The color of the border's left edge.
1600 \li \b{\c border-image} \target border-image-prop
1601 \li \l{#Border Image}{Border Image}
1602 \li The image used to fill the border. The image is cut into
1603 nine parts and stretched appropriately if necessary. See
1604 \l{#Border Image}{Border Image} for details.
1606 This property is supported by QAbstractItemView
1607 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1608 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit,
1609 QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter,
1610 QTextEdit and QToolTip.
1612 See also \l{#border-color-prop}{border-color},
1613 \l{Qt Style Sheets Reference#border-style-prop}{border-style},
1614 \l{Qt Style Sheets Reference#border-width-prop}{border-width}, and
1618 \li \b{\c border-radius} \target border-radius-prop
1619 \li \l{#Radius}{Radius}
1620 \li The radius of the border's corners. Equivalent to
1621 specifying \c border-top-left-radius, \c
1622 border-top-right-radius, \c border-bottom-right-radius,
1623 and \c border-bottom-left-radius.
1625 The border-radius clips the element's
1626 \l{Qt Style Sheets Reference#background-prop}{background}.
1628 This property is supported by QAbstractItemView
1629 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1630 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
1631 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
1634 If this property is not specified, it defaults to 0.
1638 \snippet code/doc_src_stylesheet.qdoc 45
1640 See also \l{Qt Style Sheets Reference#border-width-prop}{border-width} and
1644 \li \c border-top-left-radius
1645 \li \l{#Radius}{Radius}
1646 \li The radius of the border's top-left corner.
1649 \li \c border-top-right-radius
1650 \li \l{#Radius}{Radius}
1651 \li The radius of the border's top-right corner.
1654 \li \c border-bottom-right-radius
1655 \li \l{#Radius}{Radius}
1656 \li The radius of the border's bottom-right corner. Setting
1657 this property to a positive value results in a rounded
1661 \li \c border-bottom-left-radius
1662 \li \l{#Radius}{Radius}
1663 \li The radius of the border's bottom-left corner. Setting this
1664 property to a positive value results in a rounded corner.
1667 \li \b{\c border-style} \target border-style-prop
1668 \li \l {Border Style}
1669 \li The style of all the border's edges.
1671 This property is supported by QAbstractItemView
1672 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1673 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
1674 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
1677 If this property is not specified, it defaults to \c none.
1681 \snippet code/doc_src_stylesheet.qdoc 46
1683 See also \l{#border-color-prop}{border-color},
1684 \l{Qt Style Sheets Reference#border-style-prop}{border-style},
1685 \l{#border-image-prop}{border-image}, and \l{The Box Model}.
1688 \li \c border-top-style
1689 \li \l{#Border Style}{Border Style}
1690 \li The style of the border's top edge.
1693 \li \c border-right-style
1694 \li \l{#Border Style}{Border Style}
1695 \li The style of the border's right edge/
1698 \li \c border-bottom-style
1699 \li \l{#Border Style}{Border Style}
1700 \li The style of the border's bottom edge.
1703 \li \c border-left-style
1704 \li \l{#Border Style}{Border Style}
1705 \li The style of the border's left edge.
1708 \li \b{\c border-width} \target border-width-prop
1709 \li \l{#Box Lengths}{Box Lengths}
1710 \li The width of the border. Equivalent to setting \c
1711 border-top-width, \c border-right-width, \c
1712 border-bottom-width, and \c border-left-width.
1714 This property is supported by QAbstractItemView
1715 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1716 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
1717 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
1722 \snippet code/doc_src_stylesheet.qdoc 47
1724 See also \l{#border-color-prop}{border-color},
1725 \l{#border-radius-prop}{border-radius},
1726 \l{Qt Style Sheets Reference#border-style-prop}{border-style},
1727 \l{#border-image-prop}{border-image}, and
1731 \li \c border-top-width
1732 \li \l{#Length}{Length}
1733 \li The width of the border's top edge.
1736 \li \c border-right-width
1737 \li \l{#Length}{Length}
1738 \li The width of the border's right edge.
1741 \li \c border-bottom-width
1742 \li \l{#Length}{Length}
1743 \li The width of the border's bottom edge.
1746 \li \c border-left-width
1747 \li \l{#Length}{Length}
1748 \li The width of the border's left edge.
1751 \li \b{\c bottom} \target bottom-prop
1752 \li \l{#Length}{Length}
1753 \li If \l{#position-prop}{position} is \c relative (the
1754 default), moves a subcontrol by a certain offset up;
1755 specifying \tt{bottom: \e{y}} is then equivalent to
1756 specifying \tt{\l{Qt Style Sheets Reference#top-prop}{top}: -\e{y}}.
1758 If \l{#position-prop}{position} is \c absolute, the \c
1759 bottom property specifies the subcontrol's bottom edge
1760 in relation to the parent's bottom edge (see also
1761 \l{Qt Style Sheets Reference#subcontrol-origin-prop}
1762 {subcontrol-origin}).
1766 \snippet code/doc_src_stylesheet.qdoc 48
1768 See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{#right-prop}{right}, and
1769 \l{Qt Style Sheets Reference#top-prop}{top}.
1772 \li \b{\c button-layout} \target button-layout-prop
1773 \li \l{#Number}{Number}
1774 \li The layout of buttons in a QDialogButtonBox or
1775 a QMessageBox. The possible values are 0
1776 (\l{QDialogButtonBox::}{WinLayout}), 1
1777 (\l{QDialogButtonBox::}{MacLayout}), 2
1778 (\l{QDialogButtonBox::}{KdeLayout}), 3
1779 (\l{QDialogButtonBox::}{GnomeLayout}) and 5
1780 (\l{QDialogButtonBox::}{AndroidLayout}).
1782 If this property is not specified, it defaults to the
1783 value specified by the current style for the
1784 \l{QStyle::}{SH_DialogButtonLayout} style hint.
1788 \snippet code/doc_src_stylesheet.qdoc 49
1791 \li \b{\c color} \target color-prop
1792 \li \l{#Brush}{Brush} \br
1793 \li The color used to render text.
1795 This property is supported by all widgets that respect
1796 the \l QWidget::palette.
1798 If this property is not set, the default is whatever is
1799 set for in the widget's palette for the
1800 QWidget::foregroundRole (typically black).
1804 \snippet code/doc_src_stylesheet.qdoc 50
1806 See also \l{Qt Style Sheets Reference#background-prop}{background} and
1807 \l{#selection-color-prop}{selection-color}.
1810 \li \b{\c dialogbuttonbox-buttons-have-icons}
1811 \li \l{#Boolean}{Boolean}
1812 \li Whether the buttons in a QDialogButtonBox show icons
1814 If this property is set to 1, the buttons of a QDialogButtonBox
1815 show icons; if it is set to 0, the icons are not shown.
1817 See the \l{Qt Style Sheets Reference#list of icons}{List of Icons}
1818 section for information on how to set icons.
1820 \snippet code/doc_src_stylesheet.qdoc 51
1822 \note Styles defining this property must be applied before the
1823 QDialogButtonBox is created; this means that you must apply the
1824 style to the parent widget or to the application itself.
1828 \li \b{\c etch-disabled-text}*
1829 \li \l{#Boolean}{Boolean}
1830 \li Whether disabled text is drawn etched.
1832 If this property is not specified, it defaults to the
1833 value specified by the current style for the
1834 \l{QStyle::}{SH_EtchDisabledText} style hint.
1838 \snippet code/doc_src_stylesheet.qdoc 52
1842 \li \b{\c font} \target font-prop
1844 \li Shorthand notation for setting the text's font. Equivalent
1845 to specifying \c font-family, \c font-size, \c font-style,
1846 and/or \c font-weight.
1848 This property is supported by all widgets that respect
1849 the \l QWidget::font.
1851 If this property is not set, the default is the
1856 \snippet code/doc_src_stylesheet.qdoc 53
1861 \li The font family.
1865 \snippet code/doc_src_stylesheet.qdoc 54
1869 \li \l{#Font Size}{Font Size}
1870 \li The font size. In this version of Qt, only pt and px metrics are
1875 \snippet code/doc_src_stylesheet.qdoc 55
1884 \snippet code/doc_src_stylesheet.qdoc 56
1888 \li \l{#Font Weight}{Font Weight}
1889 \li The weight of the font.
1892 \li \b{\c gridline-color}* \target gridline-color-prop
1893 \li \l{#Color}{Color} \br
1894 \li The color of the grid line in a QTableView.
1896 If this property is not specified, it defaults to the
1897 value specified by the current style for the
1898 \l{QStyle::}{SH_Table_GridLineColor} style hint.
1902 \snippet code/doc_src_stylesheet.qdoc 57
1905 \li \b{\c height} \target height-prop
1906 \li \l{#Length}{Length}
1907 \li The height of a subcontrol (or in some case, a widget).
1909 If this property is not specified, it defaults to a value
1910 that depends on the subcontrol/widget and on the current style.
1912 \warning Unless otherwise specified, this property has no effect
1913 when set on widgets. If you want a widget with a fixed height, set
1914 the \l{#min-width-prop}{min-height} and
1915 \l{#max-width-prop}{max-height} to the same value.
1919 \snippet code/doc_src_stylesheet.qdoc 58
1921 See also \l{#width-prop}{width}.
1924 \li \b{\c icon} \target icon-prop
1926 \li The icon that is used, for widgets that have an icon.
1928 The only widget currently supporting this property is QPushButton.
1930 \note It's the application's responsibility to assign an icon to a
1931 button (using the QAbstractButton API), and not the style's. So be
1932 careful setting it unless your stylesheet is targeting a specific
1935 Available since 5.15.
1938 \li \b{\c icon-size} \target icon-size-prop
1939 \li \l{#Length}{Length}
1940 \li The width and height of the icon in a widget.
1942 The icon size of the following widgets can be set using this
1956 \li \b{\c image}* \target image-prop
1958 \li The image that is drawn in the contents rectangle of a
1961 The image property accepts a list of \l{#Url}{Url}s or
1962 an \c{svg}. The actual image that is drawn is determined
1963 using the same algorithm as QIcon (i.e) the image is never scaled
1964 up but always scaled down if necessary. If a \c{svg} is specified,
1965 the image is scaled to the size of the contents rectangle.
1967 Setting the image property on sub controls implicitly sets the
1968 width and height of the sub-control (unless the image in a SVG).
1970 In Qt 4.3 and later, the alignment of the
1971 image within the rectangle can be specified using
1972 \l{image-position-prop}{image-position}.
1974 This property is for subcontrols only--we don't support it for
1977 \warning The QIcon SVG plugin is needed to render SVG images.
1981 \snippet code/doc_src_stylesheet.qdoc 59
1984 \li \b{\c image-position} \target image-position-prop
1985 \li \l{#Alignment}{alignment}
1986 \li In Qt 4.3 and later, the alignment of the image image's position can be specified
1987 using relative or absolute position.
1990 \li \b{\c left} \target left-prop
1991 \li \l{#Length}{Length}
1992 \li If \l{#position-prop}{position} is \c relative (the
1993 default), moves a subcontrol by a certain offset to
1996 If \l{#position-prop}{position} is \c absolute, the \c
1997 left property specifies the subcontrol's left edge in
1998 relation to the parent's left edge (see also
1999 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}).
2001 If this property is not specified, it defaults to \c 0.
2005 \snippet code/doc_src_stylesheet.qdoc 60
2007 See also \l{#right-prop}{right}, \l{Qt Style Sheets Reference#top-prop}{top}, and
2008 \l{#bottom-prop}{bottom}.
2011 \li \b{\c lineedit-password-character*} \target lineedit-password-character-prop
2012 \li \l{#Number}{Number}
2013 \li The QLineEdit password character as a Unicode number.
2015 If this property is not specified, it defaults to the
2016 value specified by the current style for the
2017 \l{QStyle::}{SH_LineEdit_PasswordCharacter} style hint.
2021 \snippet code/doc_src_stylesheet.qdoc 61
2024 \li \b{\c lineedit-password-mask-delay*} \target lineedit-password-mask-delay-prop
2025 \li \l{#Number}{Number}
2026 \li The QLineEdit password mask delay in milliseconds before
2027 \l{#lineedit-password-character-prop}{lineedit-password-character} is applied to visible character.
2029 If this property is not specified, it defaults to the
2030 value specified by the current style for the
2031 \l{QStyle::}{SH_LineEdit_PasswordMaskDelay} style hint.
2033 \b{This property was added in Qt 5.4.}
2037 \snippet code/doc_src_stylesheet.qdoc 160
2041 \li \b{\c margin} \target margin-prop
2042 \li \l {Box Lengths}
2043 \li The widget's margins. Equivalent to specifying \c
2044 margin-top, \c margin-right, \c margin-bottom, and \c
2047 This property is supported by QAbstractItemView
2048 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2049 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2050 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
2053 If this property is not specified, it defaults to \c 0.
2057 \snippet code/doc_src_stylesheet.qdoc 62
2059 See also \l{Qt Style Sheets Reference#padding-prop}{padding},
2060 \l{#spacing-prop}{spacing}, and \l{The Box Model}.
2064 \li \l{#Length}{Length}
2065 \li The widget's top margin.
2069 \li \l{#Length}{Length}
2070 \li The widget's right margin.
2073 \li \c margin-bottom
2074 \li \l{#Length}{Length}
2075 \li The widget's bottom margin.
2079 \li \l{#Length}{Length}
2080 \li The widget's left margin.
2083 \li \b{\c max-height} \target max-height-prop
2084 \li \l{#Length}{Length}
2085 \li The widget's or a subcontrol's maximum height.
2087 This property is supported by QAbstractItemView
2088 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2089 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2090 QMenuBar, QPushButton, QRadioButton, QSizeGrip, QSpinBox,
2091 QSplitter, QStatusBar, QTextEdit, and QToolTip.
2093 The value is relative to the contents rect in the \l{The
2094 Box Model}{box model}.
2098 \snippet code/doc_src_stylesheet.qdoc 63
2100 See also \l{#max-width-prop}{max-width}.
2103 \li \b{\c max-width} \target max-width-prop
2104 \li \l{#Length}{Length}
2105 \li The widget's or a subcontrol's maximum width.
2107 This property is supported by QAbstractItemView
2108 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2109 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2110 QMenuBar, QPushButton, QRadioButton, QSizeGrip, QSpinBox,
2111 QSplitter, QStatusBar, QTextEdit, and QToolTip.
2113 The value is relative to the contents rect in the \l{The
2114 Box Model}{box model}.
2118 \snippet code/doc_src_stylesheet.qdoc 64
2120 See also \l{#max-height-prop}{max-height}.
2124 \li \b{\c messagebox-text-interaction-flags*} \target messagebox-text-interaction-flags-prop
2125 \li \l{#Number}{Number}
2126 \li The interaction behavior for text in a message box.
2127 Possible values are based on Qt::TextInteractionFlags.
2129 If this property is not specified, it defaults to the
2130 value specified by the current style for the
2131 \l{QStyle::}{SH_MessageBox_TextInteractionFlags} style
2136 \snippet code/doc_src_stylesheet.qdoc 65
2139 \li \b{\c min-height} \target min-height-prop
2140 \li \l{#Length}{Length}
2141 \li The widget's or a subcontrol's minimum height.
2143 This property is supported by QAbstractItemView
2144 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2145 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2146 QMenuBar, QPushButton, QRadioButton, QSizeGrip, QSpinBox,
2147 QSplitter, QStatusBar, QTextEdit, QToolButton, and QToolTip.
2149 If this property is not specified, the minimum height is
2150 derived based on the widget's contents and the style.
2152 The value is relative to the contents rect in the \l{The
2153 Box Model}{box model}.
2157 \snippet code/doc_src_stylesheet.qdoc 66
2159 \note Setting this property might allow widgets to shrink
2160 smaller than the space required for the contents.
2162 See also \l{#min-width-prop}{min-width}.
2165 \li \b{\c min-width} \target min-width-prop
2166 \li \l{#Length}{Length}
2167 \li The widget's or a subcontrol's minimum width.
2169 This property is supported by QAbstractItemView
2170 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2171 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2172 QMenuBar, QPushButton, QRadioButton, QSizeGrip, QSpinBox,
2173 QSplitter, QStatusBar, QTextEdit, QToolButton, and QToolTip.
2175 If this property is not specified, the minimum width is
2176 derived based on the widget's contents and the style.
2178 The value is relative to the contents rect in the \l{The
2179 Box Model}{box model}.
2183 \snippet code/doc_src_stylesheet.qdoc 67
2185 \note Setting this property might allow widgets to shrink
2186 smaller than the space required for the contents.
2188 See also \l{#min-height-prop}{min-height}.
2191 \li \b{\c opacity*} \target opacity-prop
2192 \li \l{#Number}{Number}
2193 \li The opacity for a widget. Possible values are from 0
2194 (transparent) to 255 (opaque). For the moment, this is
2195 only supported for \l{QToolTip}{tooltips}.
2197 If this property is not specified, it defaults to the
2198 value specified by the current style for the
2199 \l{QStyle::}{SH_ToolTipLabel_Opacity} style hint.
2203 \snippet code/doc_src_stylesheet.qdoc 68
2208 \li The outline drawn around the object's border.
2211 \li \b outline-color
2212 \li \l{#Color}{Color}
2213 \li The color of the outline.
2214 See also \l{Qt Style Sheets Reference#border-color-prop}{border-color}
2217 \li \b outline-offset
2218 \li \l{#Length}{Length}
2219 \li The outline's offset from the border of the widget.
2222 \li \b outline-style
2224 \li Specifies the pattern used to draw the outline.
2225 See also \l{Qt Style Sheets Reference#border-style-prop}{border-style}
2228 \li \b outline-radius
2230 \li Adds rounded corners to the outline
2233 \li \b outline-bottom-left-radius
2234 \li \l{#Radius}{Radius}
2235 \li The radius for the bottom-left rounded corner of the outline.
2238 \li \b outline-bottom-right-radius
2239 \li \l{#Radius}{Radius}
2240 \li The radius for the bottom-right rounded corner of the outline.
2243 \li \b outline-top-left-radius
2244 \li \l{#Radius}{Radius}
2245 \li The radius for the top-left corner of the outline.
2248 \li \b outline-top-right-radius
2249 \li \l{#Radius}{Radius}
2250 \li The radius for the top-right rounded corner of the outline.
2254 \li \b{\c padding} \target padding-prop
2255 \li \l{#Box Lengths}{Box Lengths}
2256 \li The widget's padding. Equivalent to specifying \c
2257 padding-top, \c padding-right, \c padding-bottom, and \c
2260 This property is supported by QAbstractItemView
2261 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2262 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2263 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
2266 If this property is not specified, it defaults to \c 0.
2270 \snippet code/doc_src_stylesheet.qdoc 69
2272 See also \l{#margin-prop}{margin},
2273 \l{#spacing-prop}{spacing}, and \l{The Box Model}.
2277 \li \l{#Length}{Length}
2278 \li The widget's top padding.
2281 \li \c padding-right
2282 \li \l{#Length}{Length}
2283 \li The widget's right padding.
2286 \li \c padding-bottom
2287 \li \l{#Length}{Length}
2288 \li The widget's bottom padding.
2292 \li \l{#Length}{Length}
2293 \li The widget's left padding.
2296 \li \b{\c paint-alternating-row-colors-for-empty-area}
2297 \target paint-alternating-row-colors-for-empty-area-prop
2299 \li Whether the QTreeView paints alternating row colors for the empty
2300 area (i.e the area where there are no items)
2303 \li \b{\c placeholder-text-color*} \target placeholder-text-color-prop
2304 \li \l{#Brush}{Brush} \br
2305 \li The color used for the placeholder text of text editing widgets.
2307 If this property is not set, the default value is whatever
2308 is set for the palette's \l{QPalette::}{PlaceholderText}
2313 \snippet code/doc_src_stylesheet.qdoc 163
2315 Available since 6.5.
2318 \li \b{\c position} \target position-prop
2321 \li Whether offsets specified using \l{Qt Style Sheets Reference#left-prop}{left},
2322 \l{#right-prop}{right}, \l{Qt Style Sheets Reference#top-prop}{top}, and
2323 \l{#bottom-prop}{bottom} are relative or absolute
2326 If this property is not specified, it defaults to \c
2330 \li \b{\c right} \target right-prop
2331 \li \l{#Length}{Length}
2332 \li If \l{#position-prop}{position} is \c relative (the
2333 default), moves a subcontrol by a certain offset to
2334 the left; specifying \tt{right: \e{x}} is then equivalent
2335 to specifying \tt{\l{Qt Style Sheets Reference#left-prop}{left}: -\e{x}}.
2337 If \l{#position-prop}{position} is \c absolute, the \c
2338 right property specifies the subcontrol's right edge in
2339 relation to the parent's right edge (see also
2340 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}).
2344 \snippet code/doc_src_stylesheet.qdoc 70
2346 See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{Qt Style Sheets Reference#top-prop}{top}, and
2347 \l{#bottom-prop}{bottom}.
2350 \li \b{\c selection-background-color*} \target selection-background-color-prop
2351 \li \l{#Brush}{Brush} \br
2352 \li The background of selected text or items.
2354 This property is supported by all widgets that respect
2355 the \l QWidget::palette and that show selection text.
2357 If this property is not set, the default value is
2358 whatever is set for the palette's
2359 \l{QPalette::}{Highlight} role.
2363 \snippet code/doc_src_stylesheet.qdoc 71
2365 See also \l{#selection-color-prop}{selection-color} and
2366 \l{Qt Style Sheets Reference#background-prop}{background}.
2369 \li \b{\c selection-color*} \target selection-color-prop
2370 \li \l{#Brush}{Brush} \br
2371 \li The foreground of selected text or items.
2373 This property is supported by all widgets that respect
2374 the \l QWidget::palette and that show selection text.
2376 If this property is not set, the default value is
2377 whatever is set for the palette's
2378 \l{QPalette::}{HighlightedText} role.
2382 \snippet code/doc_src_stylesheet.qdoc 72
2385 \l{#selection-background-color-prop}{selection-background-color}
2386 and \l{#color-prop}{color}.
2389 \li \b{\c show-decoration-selected*} \target show-decoration-selected-prop
2390 \li \l{#Boolean}{Boolean}
2391 \li Controls whether selections in a QListView cover the
2392 entire row or just the extent of the text.
2394 If this property is not specified, it defaults to the
2395 value specified by the current style for the
2396 \l{QStyle::}{SH_ItemView_ShowDecorationSelected} style
2401 \snippet code/doc_src_stylesheet.qdoc 73
2404 \li \b{\c spacing*} \target spacing-prop
2405 \li \l{#Length}{Length}
2406 \li Internal spacing in the widget.
2408 This property is supported by QCheckBox, checkable
2409 \l{QGroupBox}es, QMenuBar, and QRadioButton.
2411 If this property is not specified, the default value
2412 depends on the widget and on the current style.
2416 \snippet code/doc_src_stylesheet.qdoc 74
2418 See also \l{Qt Style Sheets Reference#padding-prop}{padding} and
2419 \l{#margin-prop}{margin}.
2422 \li \b{\c subcontrol-origin*} \target subcontrol-origin-prop
2423 \li \l{#Origin}{Origin}
2424 \li The origin rectangle of the subcontrol within the
2427 If this property is not specified, the default is \c
2432 \snippet code/doc_src_stylesheet.qdoc 75
2435 \l{Qt Style Sheets Reference#subcontrol-position-prop}{subcontrol-position}.
2438 \li \b{\c subcontrol-position*} \target subcontrol-position-prop
2439 \li \l{#Alignment}{Alignment}
2440 \li The alignment of the subcontrol within the origin
2441 rectangle specified by \l{Qt Style Sheets Reference#subcontrol-origin-prop}
2442 {subcontrol-origin}.
2444 If this property is not specified, it defaults to a value
2445 that depends on the subcontrol.
2449 \snippet code/doc_src_stylesheet.qdoc 76
2452 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}.
2455 \li \b{\c titlebar-show-tooltips-on-buttons}}
2456 \target titlebar-show-tooltips-on-buttons-prop
2458 \li Whether tool tips are shown on window title bar buttons.
2461 \li \b{\c widget-animation-duration*} \target widget-animation-duration
2462 \li \l{#Number}{Number}
2463 \li How much an animation should last (in milliseconds).
2464 A value equal to zero means that the animations will be disabled.
2466 If this property is not specified, it defaults to the
2467 value specified by the current style for the
2468 \l{QStyle::}{SH_Widget_Animation_Duration} style hint.
2470 \b{This property was added in Qt 5.10.}
2474 \snippet code/doc_src_stylesheet.qdoc 162
2477 \li \b{\c text-align} \target text-align-prop
2478 \li \l{#Alignment}{Alignment}
2479 \li The alignment of text and icon within the contents of the widget.
2481 If this value is not specified, it defaults to the value
2482 that depends on the native style.
2486 \snippet code/doc_src_stylesheet.qdoc 77
2488 This property is currently supported only by QPushButton
2492 \li \b{\c text-decoration}
2497 \li Additional text effects
2500 \li \b{\c top} \target top-prop
2501 \li \l{#Length}{Length}
2502 \li If \l{#position-prop}{position} is \c relative (the
2503 default), moves a subcontrol by a certain offset
2506 If \l{#position-prop}{position} is \c absolute, the \c top
2507 property specifies the subcontrol's top edge in relation
2508 to the parent's top edge (see also
2509 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}).
2511 If this property is not specified, it defaults to \c 0.
2515 \snippet code/doc_src_stylesheet.qdoc 78
2517 See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{#right-prop}{right}, and
2518 \l{#bottom-prop}{bottom}.
2521 \li \b{\c width} \target width-prop
2522 \li \l{#Length}{Length}
2523 \li The width of a subcontrol (or a widget in some cases).
2525 If this property is not specified, it defaults to a value
2526 that depends on the subcontrol/widget and on the current style.
2528 \warning Unless otherwise specified, this property has no effect
2529 when set on widgets. If you want a widget with a fixed width, set
2530 the \l{#min-width-prop}{min-width} and
2531 \l{#max-width-prop}{max-width} to the same value.
2535 \snippet code/doc_src_stylesheet.qdoc 79
2537 See also \l{#height-prop}{height}.
2540 \li \b -qt-background-role
2541 \li \l{#paletterole}{PaletteRole}
2542 \li The \c{background-color} for the subcontrol or widget based on the
2546 \li \b -qt-style-features
2548 \li The list of CSS properties that you want to apply Qt-specific styles on.
2550 \note The \c list can only include properties that are not pixmap-based.
2553 \target list of icons
2554 \section1 List of Icons
2556 Icons used in Qt can be customized using the following properties. Each of
2557 the properties listed in this section have the type \l{#Icon}{Icon}.
2559 Note that for icons to appear in buttons in a QDialogButtonBox, you need to
2560 set the dialogbuttonbox-buttons-have-icons property to true. Also, to
2561 customize the size of the icons, use the icon-size property.
2566 \li QStyle::StandardPixmap
2570 \li QStyle::SP_ArrowBack
2574 \li QStyle::SP_DriveCDIcon
2578 \li QStyle::SP_ComputerIcon
2582 \li QStyle::SP_DesktopIcon
2585 \li dialog-apply-icon
2586 \li QStyle::SP_DialogApplyButton
2589 \li dialog-cancel-icon
2590 \li QStyle::SP_DialogCancelButton
2593 \li dialog-close-icon
2594 \li QStyle::SP_DialogCloseButton
2597 \li dialog-discard-icon
2598 \li QStyle::SP_DialogDiscardButton
2601 \li dialog-help-icon
2602 \li QStyle::SP_DialogHelpButton
2606 \li QStyle::SP_DialogNoButton
2610 \li QStyle::SP_DialogOkButton
2613 \li dialog-open-icon
2614 \li QStyle::SP_DialogOpenButton
2617 \li dialog-reset-icon
2618 \li QStyle::SP_DialogResetButton
2621 \li dialog-save-icon
2622 \li QStyle::SP_DialogSaveButton
2626 \li QStyle::SP_DialogYesButton
2629 \li directory-closed-icon
2630 \li QStyle::SP_DirClosedIcon
2634 \li QStyle::SP_DirIcon
2637 \li directory-link-icon
2638 \li QStyle::SP_DirLinkIcon
2641 \li directory-open-icon
2642 \li QStyle::SP_DirOpenIcon
2645 \li dockwidget-close-icon
2646 \li QStyle::SP_DockWidgetCloseButton
2650 \li QStyle::SP_ArrowDown
2654 \li QStyle::SP_DriveDVDIcon
2658 \li QStyle::SP_FileIcon
2662 \li QStyle::SP_FileLinkIcon
2666 \li filedialog-backward-icon
2667 \li QStyle::SP_FileDialogBack
2671 \li filedialog-contentsview-icon
2672 \li QStyle::SP_FileDialogContentsView
2675 \li filedialog-detailedview-icon
2676 \li QStyle::SP_FileDialogDetailedView
2679 \li filedialog-end-icon
2680 \li QStyle::SP_FileDialogEnd
2683 \li filedialog-infoview-icon
2684 \li QStyle::SP_FileDialogInfoView
2687 \li filedialog-listview-icon
2688 \li QStyle::SP_FileDialogListView
2691 \li filedialog-new-directory-icon
2692 \li QStyle::SP_FileDialogNewFolder
2695 \li filedialog-parent-directory-icon
2696 \li QStyle::SP_FileDialogToParent
2699 \li filedialog-start-icon
2700 \li QStyle::SP_FileDialogStart
2704 \li QStyle::SP_DriveFDIcon
2708 \li QStyle::SP_ArrowForward
2712 \li QStyle::SP_DriveHDIcon
2716 \li QStyle::SP_DirHomeIcon
2719 \li lineedit-clear-button-icon
2720 \li QStyle::SP_LineEditClearButton
2724 \li QStyle::SP_ArrowLeft
2727 \li messagebox-critical-icon
2728 \li QStyle::SP_MessageBoxCritical
2731 \li messagebox-information-icon
2732 \li QStyle::SP_MessageBoxInformation
2735 \li messagebox-question-icon
2736 \li QStyle::SP_MessageBoxQuestion
2739 \li messagebox-warning-icon
2740 \li QStyle::SP_MessageBoxWarning
2744 \li QStyle::SP_DriveNetIcon
2748 \li QStyle::SP_ArrowRight
2751 \li titlebar-contexthelp-icon
2752 \li QStyle::SP_TitleBarContextHelpButton
2755 \li titlebar-maximize-icon
2756 \li QStyle::SP_TitleBarMaxButton
2759 \li titlebar-menu-icon
2760 \li QStyle::SP_TitleBarMenuButton
2763 \li titlebar-minimize-icon
2764 \li QStyle::SP_TitleBarMinButton
2767 \li titlebar-normal-icon
2768 \li QStyle::SP_TitleBarNormalButton
2771 \li titlebar-shade-icon
2772 \li QStyle::SP_TitleBarShadeButton
2775 \li titlebar-unshade-icon
2776 \li QStyle::SP_TitleBarUnshadeButton
2780 \li QStyle::SP_TrashIcon
2784 \li QStyle::SP_ArrowUp
2788 \section1 List of Property Types
2790 The following table summarizes the syntax and meaning of the
2791 different property types.
2800 \li \b Alignment \target Alignment
2806 \li Horizontal and/or vertical alignment.
2810 \snippet code/doc_src_stylesheet.qdoc 80
2813 \li \b Attachment \target Attachment
2814 \li \{ \c scroll \br
2816 \li Scroll or fixed attachment.
2819 \li \b Background \target Background
2820 \li \{ \l{#Brush}{Brush} \br
2822 | \l{#Repeat}{Repeat} \br
2823 | \l{#Alignment}{Alignment} \}*
2824 \li A sequence of \l{#Brush}{Brush}, \l{#Url}{Url},
2825 \l{#Repeat}{Repeat}, and \l{#Alignment}{Alignment}.
2828 \li \b Boolean \target Boolean
2830 \li True (\c 1) or false (\c 0).
2834 \snippet code/doc_src_stylesheet.qdoc 81
2837 \li \b Border \target Border
2838 \li \{ \l{#Border Style}{Border Style} \br
2839 | \l{#Length}{Length} \br
2840 | \l{#Brush}{Brush} \}*
2841 \li Shorthand border property.
2844 \li \b{Border Image} \target Border Image
2846 | \l{Url} \l{Number}\{4\} \br (\c stretch | \c repeat){0,2}
2847 \li A border image is an image that is composed of nine parts
2848 (top left, top center, top right, center left, center,
2849 center right, bottom left, bottom center, and bottom
2850 right). When a border of a certain size is required, the
2851 corner parts are used as is, and the top, right, bottom,
2852 and left parts are stretched or repeated to produce a
2853 border with the desired size.
2856 \l{http://www.w3.org/TR/css3-background/#the-border-image}
2857 {CSS3 Draft Specification} for details.
2860 \li \b{Border Style} \target Border Style
2863 | \c dot-dot-dash \br
2872 \li Specifies the pattern used to draw a border.
2873 See the \l{http://www.w3.org/TR/css3-background/#border-style}
2874 {CSS3 Draft Specification} for details.
2877 \li \b{Box Colors} \target Box Colors
2878 \li \l{#Brush}{Brush}\{1,4\}
2879 \li One to four occurrences of \l{#Brush}{Brush}, specifying the top,
2880 right, bottom, and left edges of a box, respectively. If
2881 the left color is not specified, it is taken to be the
2882 same as the right color. If the bottom color is not
2883 specified, it is taken to be the same as the top color. If
2884 the right color is not specified, it is taken to be the
2885 same as the top color.
2889 \snippet code/doc_src_stylesheet.qdoc 82
2892 \li \b{Box Lengths} \target Box Lengths
2893 \li \l{#Length}{Length}\{1,4\}
2894 \li One to four occurrences of \l{#Length}{Length}, specifying the
2895 top, right, bottom, and left edges of a box,
2896 respectively. If the left length is not specified, it is
2897 taken to be the same as the right length. If the bottom
2898 length is not specified, is it taken to be the same as the
2899 top length. If the right length is not specified, it is
2900 taken to be the same as the top length.
2904 \snippet code/doc_src_stylesheet.qdoc 83
2907 \li \b{Brush} \target Brush
2908 \li \l{#Color}{Color} \br
2911 \li Specifies a Color or a Gradient or an entry in the Palette.
2914 \li \b{Color} \target Color
2915 \li \tt{rgb(\e{r}, \e{g}, \e{b})} \br
2916 | \tt{rgba(\e{r}, \e{g}, \e{b}, \e{a})} \br
2917 | \tt{hsv(\e{h}, \e{s}, \e{v})} \br
2918 | \tt{hsva(\e{h}, \e{s}, \e{v}, \e{a})} \br
2919 | \tt{hsl(\e{h}, \e{s}, \e{l})} \br
2920 | \tt{hsla(\e{h}, \e{s}, \e{l}, \e{a})} \br
2921 | \tt{#\e{rrggbb}} \br
2922 | \l{QColor::fromString()}{Color Name} \br
2923 \li Specifies a color as RGB (red, green, blue), RGBA (red,
2924 green, blue, alpha), HSV (hue, saturation, value), HSVA
2925 (hue, saturation, value, alpha), HSL (hue, saturation,
2926 lightness), HSLA (hue, saturation, lightness, alpha) or a
2927 named color. The \c rgb() or \c rgba() syntax can be used
2928 with integer values between 0 and 255, or with percentages.
2929 The value of s, v, l and a in \c hsv(), \c hsva() \c hsl()
2930 or \c hsla() must all be in the range 0-255 or with
2931 percentages, the value of h must be in the range 0-359.
2932 The support for HSL(A) is available since 5.13.
2936 \snippet code/doc_src_stylesheet.qdoc 84
2938 \note The RGB colors allowed are the same as those allowed with
2940 \l{http://www.w3.org/TR/CSS21/syndata.html#color-units}{here}.
2943 \li \b{Font} \target Font
2944 \li (\l{#Font Style}{Font Style} | \l{#Font Weight}{Font Weight}){0,2} \l{#Font Size}{Font Size} String
2945 \li Shorthand font property.
2948 \li \b{Font Size} \target Font Size
2950 \li The size of a font.
2953 \li \b{Font Style} \target Font Style
2957 \li The style of a font.
2960 \li \b{Font Weight} \target Font Weight
2967 \li The weight of a font.
2970 \li \b{Gradient} \target Gradient
2971 \li \c qlineargradient \br
2972 | \c qradialgradient \br
2973 | \c qconicalgradient
2974 \li Specifies gradient fills. There are three types of gradient fills:
2977 \li \e{Linear} gradients interpolate colors between start and
2979 \li \e{Radial} gradients interpolate colors between a focal
2980 point and end points on a circle surrounding it.
2981 \li \e{Conical} gradients interpolate colors around a center
2985 Gradients are specified in Object Bounding Mode. Imagine the box
2986 in which the gradient is rendered, to have its top left corner at (0, 0)
2987 and its bottom right corner at (1, 1). Gradient parameters are
2988 then specified as percentages from 0 to 1. These values are
2989 extrapolated to actual box coordinates at runtime. It is possible
2990 specify values that lie outside the bounding box (-0.6 or 1.8, for
2993 \warning The stops have to appear sorted in ascending order.
2997 \snippet code/doc_src_stylesheet.qdoc 85
3000 \li \b{Icon} \target Icon
3001 \li (\l{#Url}{Url} (\c disabled | \c active | \c normal | \c selected)?
3002 (\c on | \c off)? )*
3003 \li A list of url, QIcon::Mode and QIcon::State.
3006 \snippet code/doc_src_stylesheet.qdoc 86
3009 \li \b{Length} \target Length
3010 \li \l{#Number}{Number} (\c px | \c pt | \c em | \c ex)?
3011 \li A number followed by a measurement unit. The CSS standard recommends
3012 that user agents must
3013 \l{http://www.w3.org/TR/CSS21/syndata.html#illegalvalues}{ignore}
3014 a declaration with an illegal value. In Qt, it is mandatory to
3015 specify measurement units. For compatibility with earlier versions
3016 of Qt, numbers without measurement units are treated as pixels
3017 in most contexts. The supported units are:
3021 \li \c pt: the size of one point (i.e., 1/72 of an inch)
3022 \li \c em: the size relative to the font size of the element
3023 (e.g., 2em means 2 times the size of the font)
3024 \li \c ex: the x-height of the font (i.e., the height of 'x')
3027 However, Qt is limited to font sizes in \c pt and \c px and any other
3028 size must be in \c px, \c em or \c ex.
3031 \li \b{Number} \target Number
3032 \li A decimal integer or a real number
3033 \li Examples: \c 0, \c 18, \c +127, \c -255, \c 12.34, \c -.5,
3037 \li \b{Origin} \target Origin
3042 \li Indicates which of four rectangles to use.
3045 \li \c margin: The margin rectangle. The margin falls outside the border.
3046 \li \c border: The border rectangle. This is where any border is drawn.
3047 \li \c padding: The padding rectangle. Unlike the margins,
3048 padding is located inside the border.
3049 \li \c content: The content rectangle. This specifies where
3050 the actual contents go, excluding any
3051 padding, border, or margin.
3054 See also \l{The Box Model}.
3057 \li \b{PaletteRole} \target PaletteRole
3058 \li \c alternate-base \br
3059 | \c accentColor \br
3061 | \c bright-text \br
3063 | \c button-text \br
3066 | \c highlighted-text \br
3069 | \c link-visited \br
3075 | \c window-text \br
3076 \li These values correspond the \l{QPalette::ColorRole}{Color roles}
3077 in the widget's QPalette.
3080 \snippet code/doc_src_stylesheet.qdoc 87
3083 \li \b{Radius} \target Radius
3084 \li \l{#Length}{Length}\{1, 2\}
3085 \li One or two occurrences of \l{#Length}{Length}. If only one length is
3086 specified, it is used as the radius of the quarter circle
3087 defining the corner. If two lengths are specified, the
3088 first length is the horizontal radius of a quarter
3089 ellipse, whereas the second length is the vertical radius.
3092 \li \b{Repeat} \target Repeat
3097 \li A value indicating the nature of repetition.
3100 \li \c repeat-x: Repeat horizontally.
3101 \li \c repeat-y: Repeat vertically.
3102 \li \c repeat: Repeat horizontally and vertically.
3103 \li \c no-repeat: Don't repeat.
3107 \li \b{Url} \target Url
3108 \li \tt{url(\e{filename})}
3109 \li \tt{\e{filename}} is the name of a file on the local disk
3110 or stored using \l{The Qt Resource System}. Setting an
3111 image implicitly sets the width and height of the element.
3115 \section1 List of Pseudo-States
3117 The following pseudo-states are supported:
3124 \row \li \c :active \target active
3125 \li This state is set when the widget resides in an active window.
3128 \li \c :adjoins-item \target adjoins-item-ps
3129 \li This state is set when the \l{#branch-sub}{::branch} of a QTreeView
3130 is adjacent to an item.
3133 \li \c :alternate \target alternate-ps
3134 \li This state is set for every alternate row whe painting the row of
3135 a QAbstractItemView when QAbstractItemView::alternatingRowColors()
3139 \li \c :bottom \target bottom-ps
3140 \li The item is positioned at the bottom. For example, a QTabBar
3141 that has its tabs positioned at the bottom.
3144 \li \c :checked \target checked-ps
3145 \li The item is checked. For example, the
3146 \l{QAbstractButton::checked}{checked} state of QAbstractButton.
3149 \li \c :closable \target closable-ps
3150 \li The items can be closed. For example, the QDockWidget has the
3151 QDockWidget::DockWidgetClosable feature turned on.
3154 \li \c :closed \target closed-ps
3155 \li The item is in the closed state. For example, an non-expanded
3159 \li \c :default \target default-ps
3160 \li The item is the default. For example, a
3161 \l{QPushButton::default}{default} QPushButton or a default action
3165 \li \c :disabled \target disabled-ps
3166 \li The item is \l{QWidget::enabled}{disabled}.
3169 \li \c :editable \target editable-ps
3170 \li The QComboBox is editable.
3173 \li \c :edit-focus \target edit-focus-ps
3174 \li The item has edit focus (See QStyle::State_HasEditFocus). This state
3175 is available only for Qt Extended applications.
3178 \li \c :enabled \target enabled-ps
3179 \li The item is \l{QWidget::enabled}{enabled}.
3182 \li \c :exclusive \target exclusive-ps
3183 \li The item is part of an exclusive item group. For example, a menu
3184 item in a exclusive QActionGroup.
3187 \li \c :first \target first-ps
3188 \li The item is the first (in a list). For example, the first
3192 \li \c :flat \target flat-ps
3193 \li The item is flat. For example, a
3194 \l{QPushButton::flat}{flat} QPushButton.
3197 \li \c :floatable \target floatable-ps
3198 \li The items can be floated. For example, the QDockWidget has the
3199 QDockWidget::DockWidgetFloatable feature turned on.
3202 \li \c :focus \target focus-ps
3203 \li The item has \l{QWidget::hasFocus()}{input focus}.
3206 \li \c :has-children \target has-children-ps
3207 \li The item has children. For example, an item in a
3208 QTreeView that has child items.
3211 \li \c :has-siblings \target has-siblings-ps
3212 \li The item has siblings. For example, an item in a
3213 QTreeView that siblings.
3216 \li \c :horizontal \target horizontal-ps
3217 \li The item has horizontal orientation
3220 \li \c :hover \target hover-ps
3221 \li The mouse is hovering over the item.
3224 \li \c :indeterminate \target indeterminate-ps
3225 \li The item has indeterminate state. For example, a QCheckBox
3226 or QRadioButton is \l{Qt::PartiallyChecked}{partially checked}.
3229 \li \c :last \target last-ps
3230 \li The item is the last (in a list). For example, the last
3234 \li \c :left \target left-ps
3235 \li The item is positioned at the left. For example, a QTabBar
3236 that has its tabs positioned at the left.
3239 \li \c :maximized \target maximized-ps
3240 \li The item is maximized. For example, a maximized QMdiSubWindow.
3243 \li \c :middle \target middle-ps
3244 \li The item is in the middle (in a list). For example, a tab
3245 that is not in the beginning or the end in a QTabBar.
3248 \li \c :minimized \target minimized-ps
3249 \li The item is minimized. For example, a minimized QMdiSubWindow.
3252 \li \c :movable \target movable-ps
3253 \li The item can be moved around. For example, the QDockWidget has the
3254 QDockWidget::DockWidgetMovable feature turned on.
3257 \li \c :no-frame \target no-frame-ps
3258 \li The item has no frame. For example, a frameless QSpinBox
3262 \li \c :non-exclusive \target non-exclusive-ps
3263 \li The item is part of a non-exclusive item group. For example, a menu
3264 item in a non-exclusive QActionGroup.
3267 \li \c :off \target off-ps
3268 \li For items that can be toggled, this applies to items
3272 \li \c :on \target on-ps
3273 \li For items that can be toggled, this applies to widgets
3277 \li \c :only-one \target only-one-ps
3278 \li The item is the only one (in a list). For example, a lone tab
3282 \li \c :open \target open-ps
3283 \li The item is in the open state. For example, an expanded
3284 item in a QTreeView, or a QComboBox or QPushButton with
3288 \li \c :next-selected \target next-selected-ps
3289 \li The next item (in a list) is selected. For example, the
3290 selected tab of a QTabBar is next to this item.
3293 \li \c :pressed \target pressed-ps
3294 \li The item is being pressed using the mouse.
3297 \li \c :previous-selected \target previous-selected-ps
3298 \li The previous item (in a list) is selected. For example, a
3299 tab in a QTabBar that is next to the selected tab.
3302 \li \c :read-only \target read-only-ps
3303 \li The item is marked read only or non-editable. For example,
3304 a read only QLineEdit or a non-editable QComboBox.
3307 \li \c :right \target right-ps
3308 \li The item is positioned at the right. For example, a QTabBar
3309 that has its tabs positioned at the right.
3312 \li \c :selected \target selected-ps
3313 \li The item is selected. For example, the selected tab in
3314 a QTabBar or the selected item in a QMenu.
3317 \li \c :top \target top-ps
3318 \li The item is positioned at the top. For example, a QTabBar
3319 that has its tabs positioned at the top.
3322 \li \c :unchecked \target unchecked-ps
3324 \l{QAbstractButton::checked}{unchecked}.
3327 \li \c :vertical \target vertical-ps
3328 \li The item has vertical orientation.
3331 \li \c :window \target window-ps
3332 \li The widget is a window (i.e top level widget)
3337 \section1 List of Sub-Controls
3339 The following subcontrols are available:
3347 \li \c ::add-line \target add-line-sub
3348 \li The button to add a line of a QScrollBar.
3351 \li \c ::add-page \target add-page-sub
3352 \li The region between the handle (slider) and the \l{#add-line-sub}{add-line}
3356 \li \c ::branch \target branch-sub
3357 \li The branch indicator of a QTreeView.
3360 \li \c ::chunk \target chunk-sub
3361 \li The progress chunk of a QProgressBar.
3364 \li \c ::close-button \target close-button-sub
3365 \li The close button of a QDockWidget or tabs of QTabBar
3368 \li \c ::corner \target corner-sub
3369 \li The corner between two scrollbars in a QAbstractScrollArea
3372 \li \c ::down-arrow \target down-arrow-sub
3373 \li The down arrow of a QComboBox, QHeaderView (sort indicator),
3374 QScrollBar or QSpinBox.
3377 \li \c ::down-button \target down-button-sub
3378 \li The down button of a QScrollBar or a QSpinBox.
3381 \li \c ::drop-down \target drop-down-sub
3382 \li The drop-down button of a QComboBox.
3385 \li \c ::float-button \target float-button-sub
3386 \li The float button of a QDockWidget
3389 \li \c ::groove \target groove-sub
3390 \li The groove of a QSlider.
3393 \li \c ::indicator \target indicator-sub
3394 \li The indicator of a QAbstractItemView, a QCheckBox, a QRadioButton,
3395 a checkable QMenu item or a checkable QGroupBox.
3398 \li \c ::handle \target handle-sub
3399 \li The handle (slider) of a QScrollBar, a QSplitter, or a QSlider.
3402 \li \c ::icon \target icon-sub
3403 \li The icon of a QAbstractItemView or a QMenu.
3406 \li \c ::item \target item-sub
3407 \li An item of a QAbstractItemView, a QMenuBar, a QMenu, or
3411 \li \c ::left-arrow \target left-arrow-sub
3412 \li The left arrow of a QScrollBar.
3415 \li \c ::left-corner \target left-corner-sub
3416 \li The left corner of a QTabWidget. For example, this control can be
3417 used to control position the left corner widget in a QTabWidget.
3420 \li \c ::menu-arrow \target menu-arrow-sub
3421 \li The arrow of a QToolButton with a menu.
3424 \li \c ::menu-button \target menu-button-sub
3425 \li The menu button of a QToolButton.
3428 \li \c ::menu-indicator \target menu-indicator-sub
3429 \li The menu indicator of a QPushButton.
3432 \li \c ::right-arrow \target right-arrow-sub
3433 \li The right arrow of a QMenu or a QScrollBar.
3436 \li \c ::pane \target pane-sub
3437 \li The pane (frame) of a QTabWidget.
3440 \li \c ::right-corner \target right-corner-sub
3441 \li The right corner of a QTabWidget. For example, this control can be
3442 used to control the position the right corner widget in a QTabWidget.
3445 \li \c ::scroller \target scroller-sub
3446 \li The scroller of a QMenu or QTabBar.
3449 \li \c ::section \target section-sub
3450 \li The section of a QHeaderView.
3453 \li \c ::separator \target separator-sub
3454 \li The separator of a QMenu or in a QMainWindow.
3457 \li \c ::sub-line \target sub-line-sub
3458 \li The button to subtract a line of a QScrollBar.
3461 \li \c ::sub-page \target sub-page-sub
3462 \li The region between the handle (slider) and the \l{#sub-line-sub}{sub-line}
3466 \li \c ::tab \target tab-sub
3467 \li The tab of a QTabBar or QToolBox.
3470 \li \c ::tab-bar \target tab-bar-sub
3471 \li The tab bar of a QTabWidget. This subcontrol exists only to
3472 control the position of the QTabBar inside the QTabWidget. To
3473 style the tabs using the \l{#tab-sub}{::tab} subcontrol.
3476 \li \c ::tear \target tear-sub
3477 \li The tear indicator of a QTabBar.
3480 \li \c ::tearoff \target tearoff-sub
3481 \li The tear-off indicator of a QMenu.
3484 \li \c ::text \target text-ps
3485 \li The text of a QAbstractItemView.
3488 \li \c ::title \target title-sub
3489 \li The title of a QGroupBox or a QDockWidget.
3492 \li \c ::up-arrow \target up-arrow-sub
3493 \li The up arrow of a QHeaderView (sort indicator), QScrollBar
3497 \li \c ::up-button \target up-button-sub
3498 \li The up button of a QSpinBox.
3502 See \l{Customizing the QPushButton's Menu Indicator Sub-Control}
3503 for an example of how to customize a subcontrol.
3507 \page stylesheet-examples.html
3508 \previouspage Qt Style Sheets Reference
3509 \title Qt Style Sheets Examples
3511 We will now see a few examples to get started with using Qt Style Sheets.
3514 \section1 Style Sheet Usage
3516 \section2 Customizing the Foreground and Background Colors
3518 Let's start by setting yellow as the background color of all
3519 \l{QLineEdit}s in an application. This could be achieved like
3522 \snippet code/doc_src_stylesheet.cpp 88
3524 If we want the property to apply only to the \l{QLineEdit}s that are
3525 children (or grandchildren or grand-grandchildren) of a specific dialog,
3526 we would rather do this:
3528 \snippet code/doc_src_stylesheet.cpp 89
3530 If we want the property to apply only to one specific QLineEdit,
3531 we can give it a name using QObject::setObjectName() and use an
3532 ID Selector to refer to it:
3534 \snippet code/doc_src_stylesheet.cpp 90
3536 Alternatively, we can set the
3537 \l{Qt Style Sheets Reference#background-prop}{background-color} property directly on the
3538 QLineEdit, omitting the selector:
3540 \snippet code/doc_src_stylesheet.cpp 91
3542 To ensure a good contrast, we should also specify a suitable
3545 \snippet code/doc_src_stylesheet.cpp 92
3547 It might be a good idea to change the colors used for selected
3550 \snippet code/doc_src_stylesheet.cpp 93
3553 \section2 Customizing Using Dynamic Properties
3555 There are many situations where we need to present a form that
3556 has mandatory fields. To indicate to the user that the field is
3557 mandatory, one effective (albeit esthetically dubious) solution
3558 is to use yellow as the background color for those fields. It
3559 turns out this is very easy to implement using Qt Style Sheets.
3560 First, we would use the following application-wide style sheet:
3562 \snippet code/doc_src_stylesheet.qdoc 94
3564 This means that every widget whose \c mandatoryField Qt property
3565 is set to true would have a yellow background.
3567 Then, for each mandatory field widget, we would simply create a
3568 \c mandatoryField property on the fly and set it to true. For
3571 \snippet code/doc_src_stylesheet.cpp 95
3573 \section2 Customizing a QPushButton Using the Box Model
3575 This time, we will show how to create a red QPushButton. This
3576 QPushButton would presumably be connected to a very destructive
3579 First, we are tempted to use this style sheet:
3581 \snippet code/doc_src_stylesheet.qdoc 96
3583 However, the result is a boring, flat button with no borders:
3585 \image stylesheet-redbutton1.png A flat red button
3587 What happened is this:
3590 \li We have made a request that cannot be satisfied using the
3591 native styles alone (e.g., the Windows Vista theme engine doesn't
3592 let us specify the background color of a button).
3593 \li Therefore, the button is rendered using style sheets.
3594 \li We haven't specified any values for
3595 \l{Qt Style Sheets Reference#border-width-prop}{border-width} and
3596 \l{Qt Style Sheets Reference#border-style-prop}{border-style}, so by default we obtain
3597 a 0-pixel wide border of style \c none.
3600 Let's improve the situation by specifying a border:
3602 \snippet code/doc_src_stylesheet.qdoc 97
3604 \image stylesheet-redbutton2.png A red button with a beige border
3606 Things look already a lot better. But the button looks a bit
3607 cramped. Let's specify some spacing between the border and the
3608 text using the \l{Qt Style Sheets Reference#padding-prop}{padding}. Additionally, we will
3609 enforce a minimum width, round the corners, and specify a larger
3610 font to make the button look nicer:
3612 \snippet code/doc_src_stylesheet.qdoc 98
3614 \image stylesheet-redbutton3.png A red button with a round beige border and big, bold text
3616 The only issue remaining is that the button doesn't react when we
3617 press it. We can fix this by specifying a slightly different
3618 background color and use a different border style.
3620 \snippet code/doc_src_stylesheet.qdoc 99
3622 \section2 Customizing the QPushButton's Menu Indicator Sub-Control
3624 Subcontrols give access to the sub-elements of a widget. For
3625 example, a QPushButton associated with a menu (using
3626 QPushButton::setMenu()) has a menu indicator. Let's customize
3627 the menu indicator for the red push button:
3629 \snippet code/doc_src_stylesheet.qdoc 100
3631 By default, the menu indicator is located at the bottom-right
3632 corner of the padding rectangle. We can change this by specifying
3633 \l{Qt Style Sheets Reference#subcontrol-position-prop}{subcontrol-position} and
3634 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin} to anchor the
3635 indicator differently. We can also use \l{Qt Style Sheets Reference#top-prop}{top} and
3636 \l{Qt Style Sheets Reference#left-prop}{left} to move the indicator by a few pixels. For
3639 \snippet code/doc_src_stylesheet.qdoc 101
3641 This positions the \c myindicator.png to the center right of the
3642 QPushButton's \l{Qt Style Sheets Reference#padding-prop}{padding} rectangle (see
3643 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin} for more
3646 \section2 Complex Selector Example
3648 Since red seems to be our favorite color, let's make the text in
3649 QLineEdit red by setting the following application-wide
3652 \snippet code/doc_src_stylesheet.qdoc 102
3654 However, we would like to give a visual indication that a
3655 QLineEdit is read-only by making it appear gray:
3657 \snippet code/doc_src_stylesheet.qdoc 103
3659 At some point, our design team comes with the requirement that
3660 all \l{QLineEdit}s in the registration form (with the
3661 \l{QObject::objectName}{object name} \c registrationDialog) to be
3664 \snippet code/doc_src_stylesheet.qdoc 104
3666 A few UI design meetings later, we decide that all our
3667 \l{QDialog}s should have brown colored \l{QLineEdit}s:
3669 \snippet code/doc_src_stylesheet.qdoc 105
3671 Quiz: What happens if we have a read-only QLineEdit in a QDialog?
3672 [Hint: The \l{The Style Sheet Syntax#Conflict Resolution}{Conflict Resolution} section above explains
3673 what happens in cases like this.]
3675 \section1 Customizing Specific Widgets
3677 This section provides examples to customize specific widgets using Style Sheets.
3679 \section2 Customizing QAbstractScrollArea
3681 The background of any QAbstractScrollArea (Item views, QTextEdit
3682 and QTextBrowser) can be set using the background properties. For example,
3683 to set a background-image that scrolls with the scroll bar:
3684 \snippet code/doc_src_stylesheet.qdoc 106
3686 If the background-image is to be fixed with the viewport:
3687 \snippet code/doc_src_stylesheet.qdoc 107
3689 \section2 Customizing QCheckBox
3691 Styling of a QCheckBox is almost identical to styling a QRadioButton. The
3692 main difference is that a tristate QCheckBox has an indeterminate state.
3694 \snippet code/doc_src_stylesheet.qdoc 108
3696 \section2 Customizing QComboBox
3698 We will look at an example where the drop down button of a QComboBox
3699 appears "merged" with the combo box frame.
3701 \snippet code/doc_src_stylesheet.qdoc 109
3703 The pop-up of the QComboBox is a QAbstractItemView and is styled using
3704 the descendant selector:
3705 \snippet code/doc_src_stylesheet.qdoc 110
3707 \section2 Customizing QDockWidget
3709 The title bar and the buttons of a QDockWidget can be customized as
3712 \snippet code/doc_src_stylesheet.qdoc 111
3714 If one desires to move the dock widget buttons to the left, the following
3715 style sheet can be used:
3717 \snippet code/doc_src_stylesheet.qdoc 112
3719 \note To customize the separator (resize handle) of a QDockWidget,
3720 use QMainWindow::separator.
3722 \section2 Customizing QFrame
3724 A QFrame is styled using the \l{The Box Model}.
3726 \snippet code/doc_src_stylesheet.qdoc 113
3728 \section2 Customizing QGroupBox
3730 Let us look at an example that moves the QGroupBox's title to
3733 \snippet code/doc_src_stylesheet.qdoc 114
3735 For a checkable QGroupBox, use the \{#indicator-sub}{::indicator} subcontrol
3736 and style it exactly like a QCheckBox (i.e)
3738 \snippet code/doc_src_stylesheet.qdoc 115
3740 \section2 Customizing QHeaderView
3742 QHeaderView is customized as follows:
3744 \snippet code/doc_src_stylesheet.qdoc 116
3746 \section2 Customizing QLineEdit
3748 The frame of a QLineEdit is styled using the \l{The Box Model}. To
3749 create a line edit with rounded corners, we can set:
3750 \snippet code/doc_src_stylesheet.qdoc 117
3752 The password character of line edits that have QLineEdit::Password
3753 echo mode can be set using:
3754 \snippet code/doc_src_stylesheet.qdoc 118
3756 The background of a read only QLineEdit can be modified as below:
3757 \snippet code/doc_src_stylesheet.qdoc 119
3759 \section2 Customizing QListView
3761 The background color of alternating rows can be customized using the following
3764 \snippet code/doc_src_stylesheet.qdoc 120
3766 To provide a special background when you hover over items, we can use the
3767 \l{item-sub}{::item} subcontrol. For example,
3769 \snippet code/doc_src_stylesheet.qdoc 121
3771 \section2 Customizing QMainWindow
3773 The separator of a QMainWindow can be styled as follows:
3775 \snippet code/doc_src_stylesheet.qdoc 122
3777 \section2 Customizing QMenu
3779 Individual items of a QMenu are styled using the 'item' subcontrol as
3782 \snippet code/doc_src_stylesheet.qdoc 123
3784 For a more advanced customization, use a style sheet as follows:
3786 \snippet code/doc_src_stylesheet.qdoc 124
3788 \section2 Customizing QMenuBar
3790 QMenuBar is styled as follows:
3792 \snippet code/doc_src_stylesheet.qdoc 125
3794 \section2 Customizing QProgressBar
3796 The QProgressBar's \l{stylesheet-reference.html#border-prop}{border},
3797 \l{stylesheet-reference.html#chunk-sub}{chunk}, and
3798 \l{stylesheet-reference.html#text-align-prop}{text-align} can be customized using
3799 style sheets. However, if one property or sub-control is customized,
3800 all the other properties or sub-controls must be customized as well.
3802 \image progressBar-stylesheet.png
3804 For example, we change the \l{stylesheet-reference.html#border-prop}
3805 {border} to grey and the \l{stylesheet-reference.html#chunk-sub}{chunk}
3808 \snippet code/doc_src_stylesheet.qdoc 126
3810 This leaves the \l{stylesheet-reference.html#text-align-prop}
3811 {text-align}, which we customize by positioning the text in the center of
3814 \snippet code/doc_src_stylesheet.qdoc 127
3816 A \l{stylesheet-reference.html#margin-prop}{margin} can be included to
3817 obtain more visible chunks.
3819 \image progressBar2-stylesheet.png
3821 In the screenshot above, we use a
3822 \l{stylesheet-reference.html#margin-prop}{margin} of 0.5 pixels.
3824 \snippet code/doc_src_stylesheet.qdoc 128
3826 \section2 Customizing QPushButton
3828 A QPushButton is styled as follows:
3829 \snippet code/doc_src_stylesheet.qdoc 129
3831 For a QPushButton with a menu, use the
3832 \l{Qt Style Sheets Reference#menu-indicator-sub}{::menu-indicator}
3835 \snippet code/doc_src_stylesheet.qdoc 130
3837 Checkable QPushButton have the \l{Qt Style Sheets Reference#checked-ps}
3838 {:checked} pseudo state set.
3840 \section2 Customizing QRadioButton
3842 The indicator of a QRadioButton can be changed using:
3843 \snippet code/doc_src_stylesheet.qdoc 131
3845 \section2 Customizing QScrollBar
3847 The QScrollBar can be styled using its subcontrols like
3848 \l{stylesheet-reference.html#handle-sub}{handle},
3849 \l{stylesheet-reference.html#add-line-sub}{add-line},
3850 \l{stylesheet-reference.html#sub-line-sub}{sub-line}, and so on. Note that
3851 if one property or sub-control is customized, all the other properties or
3852 sub-controls must be customized as well.
3854 \image stylesheet-scrollbar1.png
3856 The scroll bar above has been styled in aquamarine with a solid grey
3859 \snippet code/doc_src_stylesheet.qdoc 132
3861 \snippet code/doc_src_stylesheet.qdoc 133
3863 \snippet code/doc_src_stylesheet.qdoc 134
3865 The \l{stylesheet-reference.html#left-arrow-sub}{left-arrow} and
3866 \l{stylesheet-reference.html#right-arrow-sub}{right-arrow} have a solid grey
3867 border with a white background. As an alternative, you could also embed the
3870 \snippet code/doc_src_stylesheet.qdoc 135
3872 If you want the scroll buttons of the scroll bar to be placed together
3873 (instead of the edges) like on \macos, you can use the following
3875 \snippet code/doc_src_stylesheet.qdoc 136
3877 The scroll bar using the above stylesheet looks like this:
3878 \image stylesheet-scrollbar2.png
3881 To customize a vertical scroll bar use a style sheet similar to the following:
3882 \snippet code/doc_src_stylesheet.qdoc 137
3884 \section2 Customizing QSizeGrip
3886 QSizeGrip is usually styled by just setting an image.
3888 \snippet code/doc_src_stylesheet.qdoc 138
3890 \section2 Customizing QSlider
3892 You can style horizontal slider as below:
3893 \snippet code/doc_src_stylesheet.qdoc 139
3895 If you want to change the color of the slider parts before and after the handle, you can use the add-page
3896 and sub-page subcontrols. For example, for a vertical slider:
3898 \snippet code/doc_src_stylesheet.qdoc 140
3900 \section2 Customizing QSpinBox
3902 QSpinBox can be completely customized as below (the style sheet has commentary inline):
3904 \snippet code/doc_src_stylesheet.qdoc 141
3907 \section2 Customizing QSplitter
3909 A QSplitter derives from a QFrame and hence can be styled like a QFrame.
3910 The grip or the handle is customized using the
3911 \l{Qt Style Sheets Reference#handle-sub}{::handle} subcontrol.
3913 \snippet code/doc_src_stylesheet.qdoc 142
3915 \section2 Customizing QStatusBar
3917 We can provide a background for the status bar and a border for items
3918 inside the status bar as follows:
3919 \snippet code/doc_src_stylesheet.qdoc 143
3921 Note that widgets that have been added to the QStatusBar can be styled
3922 using the descendant declaration (i.e)
3923 \snippet code/doc_src_stylesheet.qdoc 144
3925 \section2 Customizing QTabWidget and QTabBar
3927 \image tabWidget-stylesheet1.png
3929 For the screenshot above, we need a stylesheet as follows:
3931 \snippet code/doc_src_stylesheet.qdoc 145
3933 Often we require the tabs to overlap to look like below:
3934 \image tabWidget-stylesheet2.png
3936 For a tab widget that looks like above, we make use of
3937 \l{https://doc.qt.io/qt-5/stylesheet-customizing.html#the-box-model}
3938 {negative margins}. Negative values draw the element closer to its
3939 neighbors than it would be by default. The resulting stylesheet
3942 \snippet code/doc_src_stylesheet.qdoc 146
3944 To move the tab bar to the center (as below), we require the following stylesheet:
3945 \image tabWidget-stylesheet3.png
3947 \snippet code/doc_src_stylesheet.qdoc 147
3949 The tear indicator and the scroll buttons can be further customized as follows:
3950 \snippet code/doc_src_stylesheet.qdoc 148
3952 Since Qt 4.6 the close button can be customized as follow:
3953 \snippet code/doc_src_stylesheet.qdoc 159
3955 \section2 Customizing QTableView
3957 Suppose we'd like our selected item in QTableView to have bubblegum pink
3958 fade to white as its background.
3960 \image tableWidget-stylesheet.png
3962 This is possible with the
3963 \l{stylesheet-reference.html#selection-background-color-prop}
3964 {selection-background-color} property and the syntax required is:
3966 \snippet code/doc_src_stylesheet.qdoc 149
3968 The corner widget can be customized using the following style sheet
3970 \snippet code/doc_src_stylesheet.qdoc 150
3972 The QTableView's checkbox indicator can also be customized. In the
3973 following snippet the indicator \c background-color in unchecked state is
3976 \snippet code/doc_src_stylesheet.qdoc 161
3978 \section2 Customizing QToolBar
3980 The background and the handle of a QToolBar is customized as below:
3981 \snippet code/doc_src_stylesheet.qdoc 151
3983 \section2 Customizing QToolBox
3985 The tabs of the QToolBox are customized using the 'tab' subcontrol.
3987 \snippet code/doc_src_stylesheet.qdoc 152
3989 \section2 Customizing QToolButton
3991 There are three types of QToolButtons.
3993 \li The QToolButton has no menu. In this case, the QToolButton is styled
3994 exactly like QPushButton. See
3995 \l{#Customizing QPushButton}{Customizing QPushButton} for an
3998 \li The QToolButton has a menu and has the QToolButton::popupMode set to
3999 QToolButton::DelayedPopup or QToolButton::InstantPopup. In this case,
4000 the QToolButton is styled exactly like a QPushButton with a menu.
4001 See \l{#Customizing QPushButton}{Customizing QPushButton} for an
4002 example of the usage of the menu-indicator pseudo state.
4004 \li The QToolButton has its QToolButton::popupMode set to
4005 QToolButton::MenuButtonPopup. In this case, we style it as follows:
4008 \snippet code/doc_src_stylesheet.qdoc 153
4011 \section2 Customizing QToolTip
4013 QToolTip is customized exactly like a QLabel. In addition, for platforms
4014 that support it, the opacity property may be set to adjust the opacity.
4017 \snippet code/doc_src_stylesheet.qdoc 154
4019 \section2 Customizing QTreeView
4021 The background color of alternating rows can be customized using the following
4024 \snippet code/doc_src_stylesheet.qdoc 155
4026 To provide a special background when you hover over items, we can use the
4027 \l{item-sub}{::item} subcontrol. For example,
4028 \snippet code/doc_src_stylesheet.qdoc 156
4030 The branches of a QTreeView are styled using the
4031 \l{Qt Style Sheets Reference#branch-sub}{::branch} subcontrol. The
4032 following stylesheet color codes the various states when drawing
4035 \snippet code/doc_src_stylesheet.qdoc 157
4037 Colorful, though it is, a more useful example can be made using the
4042 \li \inlineimage stylesheet-vline.png
4043 \li \inlineimage stylesheet-branch-more.png
4044 \li \inlineimage stylesheet-branch-end.png
4045 \li \inlineimage stylesheet-branch-closed.png
4046 \li \inlineimage stylesheet-branch-open.png
4051 \li branch-closed.png
4055 \snippet code/doc_src_stylesheet.qdoc 158
4057 The resulting tree view looks like this:
4059 \image stylesheet-treeview.png
4061 \sa {Supported HTML Subset}, QStyle
4064 \section1 Common Mistakes
4066 This section lists some common mistakes when using stylesheets.
4068 \section2 QPushButton and images
4070 When styling a QPushButton, it is often desirable to use an image as the
4071 button graphic. It is common to try the
4072 \l{Qt Style Sheets Reference#background-image-prop}{background-image}
4074 but this has a number of drawbacks: For instance, the background will
4075 often appear hidden behind the button decoration, because it is not
4076 considered a background. In addition, if the button is resized, the
4077 entire background will be stretched or tiled, which does not
4080 It is better to use the
4081 \l{Qt Style Sheets Reference#border-image-prop}{border-image}
4082 property, as it will always display the image,
4083 regardless of the background (you can combine it with a background if it
4084 has alpha values in it), and it has special settings to deal with button
4087 Consider the following snippet:
4089 \snippet stylesheet/common-mistakes.cpp 1
4091 This will produce a button looking like this:
4093 \image stylesheet-border-image-normal.png
4095 The numbers after the url gives the top, right, bottom and left number of
4096 pixels, respectively. These numbers correspond to the border and should not
4097 stretch when the size changes.
4098 Whenever you resize the button, the middle part of the image will stretch
4099 in both directions, while the pixels specified in the stylesheet
4100 will not. This makes the borders of the button look more natural, like
4105 \li \inlineimage stylesheet-border-image-stretched.png
4112 \li \inlineimage stylesheet-border-image-wrong.png