Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
stylesheet.qdoc
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page stylesheet.html
6 \title Qt Style Sheets
7 \brief How to use style sheets to customize the appearance of widgets.
8
9 \ingroup frameworks-technologies
10 \ingroup qt-basic-concepts
11 \ingroup qt-gui-concepts
12
13 \previouspage {Styles and Style Aware Widgets}{Styles}
14 \nextpage The Style Sheet Syntax
15
16 \keyword style sheet
17 \keyword stylesheet
18
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.
25
26 Topics:
27
28 \list
29 \li \l{Overview}
30 \li \l{The Style Sheet Syntax}
31 \li \l{Qt Widgets 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}
35 \endlist
36
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.
41
42 \target overview
43 \section1 Overview
44
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.
51
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:
55
56 \snippet code/doc_src_stylesheet.qdoc 0
57
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
64 native theme engine.
65
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.
71
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, \QD
79 provides style sheet integration, making it easy to view the effects
80 of a style sheet in different \l{QStyle}{widget styles}.
81
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}.
89
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).
95
96 Since Qt 4.5, Qt style sheets fully supports \macos.
97
98*/
99
100/*!
101 \page stylesheet-syntax.html
102 \previouspage Qt Style Sheets
103 \nextpage Qt Widgets Designer Integration
104 \title The Style Sheet Syntax
105
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.
109
110 \section1 Style Rules
111
112 Style sheets consist of a sequence of style rules. A \e{style
113 rule} is made up of a selector and a declaration. The
114 \e{selector} specifies which widgets are affected by the rule;
115 the \e{declaration} specifies which properties should be set on
116 the widget. For example:
117
118 \snippet code/doc_src_stylesheet.qdoc 1
119
120 In the above style rule, \c QPushButton is the selector and \c{{
121 color: red }} is the declaration. The rule specifies that
122 QPushButton and its subclasses (e.g., \c MyPushButton) should use
123 red as their foreground color.
124
125 Qt Style Sheet is generally case insensitive (i.e., \c color,
126 \c Color, \c COLOR, and \c cOloR refer to the same property).
127 The only exceptions are class names,
128 \l{QObject::setObjectName()}{object names}, and Qt property
129 names, which are case sensitive.
130
131 Several selectors can be specified for the same declaration,
132 using commas (\c{,}) to separate the selectors. For example,
133 the rule
134
135 \snippet code/doc_src_stylesheet.qdoc 2
136
137 is equivalent to this sequence of three rules:
138
139 \snippet code/doc_src_stylesheet.qdoc 3
140
141 The declaration part of a style rule is a list of
142 \tt{\e{property}: \e{value}} pairs, enclosed in braces (\c{{}})
143 and separated with semicolons. For example:
144
145 \snippet code/doc_src_stylesheet.qdoc 4
146
147 See the \l{List of Properties} section below for the list of
148 properties provided by Qt widgets.
149
150 \section1 Selector Types
151
152 All the examples so far used the simplest type of selector, the
153 Type Selector. Qt Style Sheets support all the
154 \l{http://www.w3.org/TR/REC-CSS2/selector.html#q1}{selectors
155 defined in CSS2}. The table below summarizes the most useful
156 types of selectors.
157
158 \table 100%
159 \header
160 \li Selector
161 \li Example
162 \li Explanation
163
164 \row
165 \li Universal Selector
166 \li \c *
167 \li Matches all widgets.
168
169 \row
170 \li Type Selector
171 \li \c QPushButton
172 \li Matches instances of QPushButton and of its subclasses.
173
174 \row
175 \li Property Selector
176 \li \c{QPushButton[flat="false"]}
177 \li Matches instances of QPushButton that are not
178 \l{QPushButton::}{flat}. You may use this selector to test
179 for any Qt \l{Qt's Property System}{property} that supports
180 QVariant::toString() (see the \l{QVariant::}{toString()}
181 function documentation for details). In addition, the
182 special \c class property is supported, for the name of the
183 class.
184
185 This selector may also be used to test dynamic properties.
186 For more information on customization using dynamic properties,
187 refer to \l{Customizing Using Dynamic Properties}.
188
189 Instead of \c =, you can also use \c ~= to test whether a
190 Qt property of type QStringList contains a given QString.
191
192 \warning If the value of the Qt property changes after the
193 style sheet has been set, it might be necessary to force a
194 style sheet recomputation. One way to achieve this is to
195 unset the style sheet and set it again.
196
197 \row
198 \li Class Selector
199 \li \c .QPushButton
200 \li Matches instances of QPushButton, but not of its subclasses.
201
202 This is equivalent to \c{*[class~="QPushButton"]}.
203
204 \row
205 \li ID \target ID Selector
206 Selector
207 \li \c{QPushButton#okButton}
208 \li Matches all QPushButton instances whose
209 \l{QObject::objectName}{object name} is \c okButton.
210
211 \row
212 \li Descendant Selector
213 \li \c{QDialog QPushButton}
214 \li Matches all instances of QPushButton that are descendants
215 (children, grandchildren, etc.) of a QDialog.
216
217 \row
218 \li Child Selector
219 \li \c{QDialog > QPushButton}
220 \li Matches all instances of QPushButton that are direct
221 children of a QDialog.
222 \endtable
223
224 \section1 Sub-Controls
225
226 For styling complex widgets, it is necessary to access subcontrols of the
227 widget, such as the drop-down button of a QComboBox or the up and down
228 arrows of a QSpinBox. Selectors may contain \e{subcontrols} that make it
229 possible to restrict the application of a rule to specific widget
230 subcontrols. For example:
231
232 \snippet code/doc_src_stylesheet.qdoc 5
233
234 The above rule styles the drop-down button of all \l{QComboBox}es.
235 Although the double-colon (\c{::}) syntax is reminiscent of CSS3
236 Pseudo-Elements, Qt Sub-Controls differ conceptually from these and have
237 different cascading semantics.
238
239 Sub-controls are always positioned with respect to another element - a
240 reference element. This reference element could be the widget or another
241 Sub-control. For example, the \l{Qt Style Sheets Reference#drop-down-sub}
242 {::drop-down} of a QComboBox is placed, by default, in the top right corner
243 of the Padding rectangle of the QComboBox. The
244 \l{Qt Style Sheets Reference#drop-down-sub}{::drop-down} is placed,
245 by default, in the Center of the Contents rectangle of the
246 \l{Qt Style Sheets Reference#drop-down-sub}{::drop-down} Sub-control. See
247 the \l{List of Stylable Widgets} below for the Sub-controls to use to
248 style a widget and their default positions.
249
250 The origin rectangle to be used can be changed using the
251 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}
252 property. For example, if we want to place the drop-down in the margin
253 rectangle of the QComboBox instead of the default Padding rectangle, we
254 can specify:
255
256 \snippet code/doc_src_stylesheet.qdoc 6
257
258 The alignment of the drop-down within the Margin rectangle is changed
259 using \l{Qt Style Sheets Reference#subcontrol-position-prop}
260 {subcontrol-position} property.
261
262 The \l{Qt Style Sheets Reference#width-prop}{width} and
263 \l{Qt Style Sheets Reference#height-prop}{height} properties can be used
264 to control the size of the Sub-control. Note that setting a
265 \l{Qt Style Sheets Reference#image-prop}{image} implicitly sets the size
266 of a Sub-control.
267
268 The relative positioning scheme
269 (\l{Qt Style Sheets Reference#position-prop}{position} : relative),
270 allows the position of the Sub-Control to be offset from its initial
271 position. For example, when the QComboBox's drop-down button is
272 pressed, we might like the arrow inside to be offset to give a
273 "pressed" effect. To achieve this, we can specify:
274
275 \snippet code/doc_src_stylesheet.qdoc 7
276
277 The absolute positioning scheme
278 (\l{Qt Style Sheets Reference#position-prop}{position} : absolute),
279 allows the position and size of the Sub-control to be changed with
280 respect to the reference element.
281
282 Once positioned, they are treated the same as widgets and can be styled
283 using the \l{box model}.
284
285 See the \l{List of Sub-Controls} below for a list of supported
286 sub-controls, and \l{Customizing the QPushButton's Menu Indicator
287 Sub-Control} for a realistic example.
288
289 \note With complex widgets such as QComboBox and QScrollBar, if one
290 property or sub-control is customized, \b{all} the other properties or
291 sub-controls must be customized as well.
292
293 \section1 Pseudo-States
294
295 Selectors may contain \e{pseudo-states} that denote that restrict
296 the application of the rule based on the widget's state.
297 Pseudo-states appear at the end of the selector, with a colon
298 (\c{:}) in between. For example, the following rule applies when
299 the mouse hovers over a QPushButton:
300
301 \snippet code/doc_src_stylesheet.qdoc 8
302
303 Pseudo-states can be negated using the exclamation operator. For
304 example, the following rule applies when the mouse does not hover
305 over a QRadioButton:
306
307 \snippet code/doc_src_stylesheet.qdoc 9
308
309 Pseudo-states can be chained, in which case a logical AND is
310 implied. For example, the following rule applies to when the
311 mouse hovers over a checked QCheckBox:
312
313 \snippet code/doc_src_stylesheet.qdoc 10
314
315 Negated Pseudo-states may appear in Pseudo-state chains. For example,
316 the following rule applies when the mouse hovers over a QPushButton
317 that is not pressed:
318
319 \snippet code/doc_src_stylesheet.qdoc 11
320
321 If needed, logical OR can be expressed using the comma operator:
322
323 \snippet code/doc_src_stylesheet.qdoc 12
324
325 Pseudo-states can appear in combination with subcontrols. For
326 example:
327
328 \snippet code/doc_src_stylesheet.qdoc 13
329
330 See the \l{List of Pseudo-States} section below for the list of
331 pseudo-states provided by Qt widgets.
332
333 \section1 Conflict Resolution
334
335 Conflicts arise when several style rules specify the same
336 properties with different values. Consider the following style
337 sheet:
338
339 \snippet code/doc_src_stylesheet.qdoc 14
340
341 Both rules match QPushButton instances called \c okButton and
342 there is a conflict for the \c color property. To resolve this
343 conflict, we must take into account the \e specificity of the
344 selectors. In the above example, \c{QPushButton#okButton} is
345 considered more specific than \c QPushButton, because it
346 (usually) refers to a single object, not to all instances of a
347 class.
348
349 Similarly, selectors with pseudo-states are more specific than
350 ones that do not specify pseudo-states. Thus, the following style
351 sheet specifies that a \l{QPushButton} should have white text
352 when the mouse is hovering over it, otherwise red text:
353
354 \snippet code/doc_src_stylesheet.qdoc 15
355
356 Here's a tricky one:
357
358 \snippet code/doc_src_stylesheet.qdoc 16
359
360 Here, both selectors have the same specificity, so if the mouse
361 hovers over the button while it is enabled, the second rule takes
362 precedence. If we want the text to be white in that case, we can
363 reorder the rules like this:
364
365 \snippet code/doc_src_stylesheet.qdoc 17
366
367 Alternatively, we can make the first rule more specific:
368
369 \snippet code/doc_src_stylesheet.qdoc 18
370
371 A similar issue arises in conjunction with Type Selectors.
372 Consider the following example:
373
374 \snippet code/doc_src_stylesheet.qdoc 19
375
376 Both rules apply to QPushButton instances (since QPushButton
377 inherits QAbstractButton) and there is a conflict for the
378 \l{Qt Style Sheets Reference#color-prop}{color} property. Because QPushButton
379 inherits QAbstractButton, it might be tempting to assume that
380 \c QPushButton is more specific than \c QAbstractButton. However,
381 for style sheet computations, all Type Selectors have the same
382 specificity, and the rule that appears last takes precedence. In
383 other words, \l{Qt Style Sheets Reference#color-prop}{color} is set to \c gray
384 for all \l{QAbstractButton}s, including \l{QPushButton}s. If we really
385 want \l{QPushButton}s to have red text, we can always reorder the
386 rules.
387
388 For determining the specificity of a rule, Qt Style Sheets follow
389 the
390 \l{http://www.w3.org/TR/REC-CSS2/cascade.html#specificity}{CSS2
391 Specification}:
392
393 \quotation
394 \e{A selector's specificity is calculated as follows:}
395
396 \list
397 \li \e{count the number of ID attributes in the selector (= a)}
398 \li \e{count the number of other attributes and pseudo-classes in the selector (= b)}
399 \li \e{count the number of element names in the selector (= c)}
400 \li \e{ignore pseudo-elements [i.e., \l{subcontrols}].}
401 \endlist
402
403 \e{Concatenating the three numbers a-b-c (in a number system with a
404 large base) gives the specificity.}
405
406 \e{Some examples:}
407
408 \snippet code/doc_src_stylesheet.qdoc 20
409 \endquotation
410
411 \section1 Cascading
412
413 Style sheets can be set on the QApplication, on parent widgets,
414 and on child widgets. An arbitrary widget's effective style sheet
415 is obtained by merging the style sheets set on the widget's
416 ancestors (parent, grandparent, etc.), as well as any style sheet
417 set on the QApplication.
418
419 When conflicts arise, the widget's own style sheet is always
420 preferred to any inherited style sheet, irrespective of the
421 specificity of the conflicting rules. Likewise, the parent
422 widget's style sheet is preferred to the grandparent's, etc.
423
424 One consequence of this is that setting a style rule on a widget
425 automatically gives it precedence over other rules specified in
426 the ancestor widgets' style sheets or the QApplication style
427 sheet. Consider the following example. First, we set a style
428 sheet on the QApplication:
429
430 \snippet code/doc_src_stylesheet.cpp 21
431
432 Then we set a style sheet on a QPushButton object:
433
434 \snippet code/doc_src_stylesheet.cpp 22
435
436 The style sheet on the QPushButton forces the QPushButton (and
437 any child widget) to have blue text, in spite of the more
438 specific rule set provided by the application-wide style sheet.
439
440 The result would have been the same if we had written
441
442 \snippet code/doc_src_stylesheet.cpp 23
443
444 except that if the QPushButton had children (which is unlikely),
445 the style sheet would have no impact on them.
446
447 Style sheet cascading is a complex topic. Refer to the
448 \l{http://www.w3.org/TR/CSS2/cascade.html#cascade}{CSS2
449 Specification} for the gory details. Be aware that Qt currently
450 doesn't implement \c{!important}.
451
452 \section1 Inheritance
453
454 In classic CSS, when font and color of an item is not explicitly set,
455 it gets automatically inherited from the parent. By default, when using
456 Qt Style Sheets, a widget does \b{not} automatically inherit its font
457 and color setting from its parent widget.
458
459 For example, consider a QPushButton inside a QGroupBox:
460
461 \snippet code/doc_src_stylesheet.cpp 24
462
463 The QPushButton does not have an explicit color set. Hence, instead
464 of inheriting color of its parent QGroupBox, it has the system color.
465 If we want to set the color on a QGroupBox and its children,
466 we can write:
467
468 \snippet code/doc_src_stylesheet.cpp 25
469
470 In contrast, setting a font and palette using QWidget::setFont() and
471 QWidget::setPalette() propagates to child widgets.
472
473 If you would prefer that the font and palette propagate to child widgets,
474 you can set the Qt::AA_UseStyleSheetPropagationInWidgetStyles flag, like
475 this:
476
477 Usage:
478 \snippet code/doc_src_stylesheet.cpp 96
479
480 When the widget-style font and palette propagation is enabled, font and
481 palette changes made through Qt Style Sheets will behave as if the user
482 had manually called the corresponding QWidget::setPalette() and
483 QWidget::setFont() methods on all of the QWidgets targeted by the style
484 sheet.
485
486 \list
487 \li Changes made by a style sheet are propagated.
488 They are pushed to all widgets matching the style sheet once, at the time
489 the change is made.
490 \li Changes made by calling QWidget::setPalette() or QWidget::setFont() are
491 inherited.
492 They are inherited by all existing and future children, where the respective
493 brush or font hasn't been explicitly set.
494 \endlist
495
496 \section1 Widgets Inside C++ Namespaces
497
498 The Type Selector can be used to style widgets of a particular type. For
499 example,
500
501 \snippet code/doc_src_stylesheet.cpp 26
502
503 Qt Style Sheet uses QObject::className() of the widget to determine
504 when to apply the Type Selector. When custom widgets are inside namespaces,
505 the QObject::className() returns <namespace>::<classname>. This conflicts
506 with the syntax for \l{Sub-Controls}. To overcome this problem,
507 when using the Type Selector for widgets inside namespaces, we must
508 replace the \c{::} with \c{--}. For example,
509
510 \snippet code/doc_src_stylesheet.cpp 27
511
512 \section1 Setting QObject Properties
513
514 From 4.3 and above, any designable Q_PROPERTY
515 can be set using the qproperty-<property name> syntax.
516
517 For example,
518 \snippet code/doc_src_stylesheet.qdoc 28
519
520 If the property references an enum declared with Q_ENUM, you should
521 reference its constants by name, not their numeric value.
522
523 \note Use the qproperty syntax with care, as it modifies the
524 widget that is being painted. Also, the qproperty syntax is evaluated only
525 once, which is when the widget is polished by the style. This means that any
526 attempt to use them in pseudo-states such as QPushButton:hover, will not work.
527*/
528
529/*!
530 \page stylesheet-designer.html
531 \previouspage The Style Sheet Syntax
532 \nextpage Customizing Qt Widgets Using Style Sheets
533 \title Qt Widgets Designer Integration
534
535 \l{Qt Widgets Designer Manual}{\QD} is an excellent tool
536 to preview style sheets. You can right-click on any widget in Designer
537 and select \uicontrol{Change styleSheet...} to set the style sheet.
538
539 \image designer-stylesheet-options.webp
540 {Editing a form in Qt Widgets Designer}
541
542 \QD also includes a style sheet syntax highlighter and validator. The
543 validator indicates if the syntax is valid or invalid, at the bottom left
544 of the \uicontrol{Edit Style Sheet} dialog.
545
546 \image designer-validator-highlighter.webp
547 {Editing and validating a stylesheet}
548
549 When you click \uicontrol{OK} or \uicontrol{Apply}, \QD will automatically display
550 the widget with its new stylesheet.
551
552 \image designer-stylesheet-usage.webp
553 {Preview of a form with the new stylesheet}
554 */
555
556/*!
557 \page stylesheet-customizing.html
558 \previouspage Qt Widgets Designer Integration
559 \nextpage Qt Style Sheets Reference
560 \title Customizing Qt Widgets Using Style Sheets
561
562 When using style sheets, every widget is treated as a box with four
563 concentric rectangles: the margin rectangle, the border rectangle, the
564 padding rectangle, and the content rectangle. The box model describes
565 this in further detail.
566
567 \target box model
568 \section1 The Box Model
569
570 The four concentric rectangles appear conceptually as below:
571
572 \image stylesheet-boxmodel.png
573 {Diagram of the CSS box model for layout design}
574
575 \list
576 \li The margin falls outside the border.
577 \li The border is drawn between the margin and the padding.
578 \li The padding falls inside the border, between the border and
579 the actual contents.
580 \li The content is what is left from the original widget or
581 subcontrol once we have removed the margin, the border, and
582 the padding.
583 \endlist
584
585 The \l{Qt Style Sheets Reference#margin-prop}{margin},
586 \l{Qt Style Sheets Reference#border-width-prop}
587 {border-width}, and
588 \l{Qt Style Sheets Reference#padding-prop}{padding}
589 properties all default to zero. In that case, all four rectangles
590 (\c margin, \c border, \c padding, and \c content) coincide exactly.
591
592 You can specify a background for the widget using the
593 \l{Qt Style Sheets Reference#background-image-prop}{background-image}
594 property. By default, the background-image is drawn only for the area
595 inside the border. This can be changed using the
596 \l{Qt Style Sheets Reference#background-clip-prop}{background-clip}
597 property. You can use
598 \l{Qt Style Sheets Reference#background-repeat-prop}{background-repeat}
599 and
600 \l{Qt Style Sheets Reference#background-origin-prop}{background-origin}
601 to control the repetition and origin of the background image.
602
603 A background-image does not scale with the size of the widget. To provide
604 a "skin" or background that scales along with the widget size, one must
605 use
606 \l{Qt Style Sheets Reference#border-image-prop}{border-image}. Since the
607 border-image property provides an alternate background, it is not required
608 to specify a background-image when border-image is specified. In the case,
609 when both of them are specified, the border-image draws over the
610 background-image.
611
612 In addition, the \l{Qt Style Sheets Reference#image-prop}{image} property
613 may be used to draw an image over the border-image. The image specified does
614 not tile or stretch and when its size does not match the size of the widget,
615 its alignment is specified using the
616 \l{Qt Style Sheets Reference#image-position-prop}{image-position}
617 property. Unlike background-image and border-image, one may specify a
618 SVG in the image property, in which case the image is scaled automatically
619 according to the widget size.
620
621 The steps to render a rule are as follows:
622 \list
623 \li Set clip for entire rendering operation (border-radius)
624 \li Draw the background (background-image)
625 \li Draw the border (border-image, border)
626 \li Draw overlay image (image)
627 \endlist
628
629 \target sub controls
630 \section1 Sub-controls
631
632 A widget is considered as a hierarchy (tree) of subcontrols drawn on top
633 of each other. For example, the QComboBox draws the drop-down sub-control
634 followed by the down-arrow sub-control. A QComboBox is thus rendered as
635 follows:
636 \list
637 \li Render the QComboBox { } rule
638 \li Render the QComboBox::drop-down { } rule
639 \li Render the QComboBox::down-arrow { } rule
640 \endlist
641
642 Sub-controls share a parent-child relationship. In the case of QComboBox,
643 the parent of down-arrow is the drop-down and the parent of drop-down is
644 the widget itself. Sub-controls are positioned within their parent using
645 the \l{Qt Style Sheets Reference#subcontrol-position-prop}
646 {subcontrol-position} and
647 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}
648 properties.
649
650 Once positioned, sub-controls can be styled using the \l{box model}.
651
652 \note With complex widgets such as QComboBox and QScrollBar, if one
653 property or sub-control is customized, \b{all} the other properties or
654 sub-controls must be customized as well.
655
656*/
657
658/*!
659 \page stylesheet-reference.html
660 \previouspage Customizing Qt Widgets Using Style Sheets
661 \nextpage Qt Style Sheets Examples
662 \title Qt Style Sheets Reference
663
664 Qt Style Sheets support various properties, pseudo-states, and
665 subcontrols that make it possible to customize the look of
666 widgets.
667
668 \section1 List of Stylable Widgets
669
670 The following table lists the Qt widgets that can be customized
671 using style sheets:
672
673 \table 100%
674 \header
675 \li Widget
676 \li How to Style
677
678 \row
679 \li QAbstractScrollArea \target qabstractscrollarea-widget
680 \li Supports the \l{box model}.
681 \br
682 \br
683 All derivatives of QAbstractScrollArea, including QTextEdit,
684 and QAbstractItemView (all item view classes), support
685 scrollable backgrounds using
686 \l{Qt Style Sheets Reference#background-attachment-prop}
687 {background-attachment}. Setting the background-attachment to
688 \c{fixed} provides a background-image that does not scroll with the
689 viewport. Setting the background-attachment to \c{scroll}, scrolls
690 the background-image when the scroll bars move.
691 \br
692 \br
693 See \l{Qt Style Sheets Examples#Customizing QAbstractScrollArea}
694 {Customizing QAbstractScrollArea} for an example.
695
696 \row
697 \li QCheckBox \target qcheckbox-widget
698 \li Supports the \l{box model}. The check indicator can be
699 styled using the \l{#indicator-sub}{::indicator}
700 subcontrol. By default, the indicator is placed in the Top
701 Left corner of the Contents rectangle of the widget.
702 \br
703 \br
704 The \l{#spacing-prop}{spacing} property
705 specifies the spacing between the check indicator and
706 the text.
707 \br
708 \br
709 See \l{Qt Style Sheets Examples#Customizing QCheckBox}
710 {Customizing QCheckBox} for an example.
711
712 \row
713 \li QColumnView \target qcolumnview-widget
714 \li The grip can be styled by using the \l{image-prop}{image} property.
715 \br
716 \br
717 The arrow indicators can by styled using the
718 \l{left-arrow-sub}{::left-arrow} subcontrol and the
719 \l{right-arrow-sub}{::right-arrow} subcontrol.
720
721 \row
722 \li QComboBox \target qcombobox-widget
723 \li The frame around the combobox can be styled using the
724 \l{box model}.
725 \br
726 \br
727 The drop-down button can be styled using
728 the \l{#drop-down-sub}{::drop-down} subcontrol. By default, the
729 drop-down button is placed in the top right corner of the padding
730 rectangle of the widget.
731 \br
732 \br
733 The arrow mark inside the drop-down button
734 can be styled using the \l{#down-arrow-sub}{::down-arrow}
735 subcontrol. By default, the arrow is placed in the center of the
736 contents rectangle of the drop-down subcontrol.
737 \br
738 \br
739 The color of the placeholder text can be set using the
740 \l{#placeholder-text-color-prop}{placeholder-text-color} property.
741 \br
742 \br
743 See \l{Qt Style Sheets Examples#Customizing QComboBox}{Customizing QComboBox}
744 for an example.
745
746 \row
747 \li QDateEdit \target qdateedit-widget
748 \li See \l{#qspinbox-widget}{QSpinBox}.
749
750 \row
751 \li QDateTimeEdit \target qdatetimeedit-widget
752 \li See \l{#qspinbox-widget}{QSpinBox}.
753
754 \row
755 \li QDialog \target qdialog-widget
756 \li Supports only the \l{Qt Style Sheets Reference#background-prop}{background},
757 \l{#background-clip-prop}{background-clip} and
758 \l{#background-origin-prop}{background-origin} properties.
759
760 \warning Make sure you define the Q_OBJECT macro for your custom
761 widget.
762
763 \row
764 \li QDialogButtonBox \target qdialogbuttonbox-widget
765 \li The layout of buttons can be altered using the
766 \l{#button-layout-prop}{button-layout} property.
767
768 \row
769 \li QDockWidget \target qdockwidget-widget
770 \li Supports styling of the title bar and the title bar buttons when docked.
771 \br
772 \br
773 The dock widget border can be styled using the \l{#border-prop}{border}
774 property. The \l{#title-sub}{::title} subcontrol can be used to customize
775 the title bar. The close and float buttons are positioned with respect
776 to the \l{title-sub}{::title} subcontrol using the
777 \l{#close-button-sub}{::close-button} and
778 \l{#float-button-sub}{::float-button} respectively.
779 \br
780 \br
781 When the title bar is vertical, the \l{#vertical-ps}{:vertical} pseudo
782 class is set. In addition, depending on QDockWidget::DockWidgetFeature,
783 the \l{#closable-ps}{:closable}, \l{#floatable-ps}{:floatable} and
784 \l{#movable-ps}{:movable} pseudo states are set.
785
786 \note Use QMainWindow::separator to style the resize handle.
787
788 \warning The style sheet has no effect when the QDockWidget is undocked
789 as Qt uses native top level windows when undocked.
790
791 See \l{Qt Style Sheets Examples#Customizing QDockWidget}
792 {Customizing QDockWidget} for an example.
793
794 \row
795 \li QDoubleSpinBox \target qdoublespinbox-widget
796 \li See \l{#qspinbox-widget}{QSpinBox}.
797
798 \row
799 \li QFrame \target qframe-widget
800 \li Supports the \l{box model}.
801 \br
802 \br
803 Since 4.3, setting a stylesheet on a QLabel automatically
804 sets the QFrame::frameStyle property to QFrame::StyledPanel.
805 \br
806 \br
807 See \l{Qt Style Sheets Examples#Customizing QFrame}{Customizing QFrame}
808 for an example.
809
810 \row
811 \li QGroupBox \target qgroupbox-widget
812 \li Supports the \l{box model}.
813 \br
814 \br
815 The title can be styled using the
816 \l{#title-sub}{::title} subcontrol. By default, the title is placed
817 depending on QGroupBox::textAlignment.
818 \br
819 \br
820 In the case of a checkable QGroupBox, the title includes the
821 check indicator. The indicator is styled using the
822 \l{#indicator-sub}{::indicator} subcontrol. The
823 \l{#spacing-prop}{spacing} property can be used to control
824 the spacing between the text and indicator.
825 \br
826 \br
827 See \l{Qt Style Sheets Examples#Customizing QGroupBox}{Customizing QGroupBox}
828 for an example.
829
830 \row
831 \li QHeaderView \target qheaderview-widget
832 \li Supports the \l{box model}.
833 \br
834 \br
835 The sections of the header view are
836 styled using the \l{#section-sub}{::section} sub control. The
837 \c{section} Sub-control supports the \l{#middle-ps}{:middle},
838 \l{#first-ps}{:first}, \l{#last-ps}{:last},
839 \l{#only-one-ps}{:only-one}, \l{#next-selected-ps}{:next-selected},
840 \l{#previous-selected-ps}{:previous-selected},
841 \l{#selected-ps}{:selected},
842 and \l{#checked-ps}{:checked} pseudo states.
843 \br
844 \br
845 The sort indicator can be styled using the
846 \l{#up-arrow-sub}{::up-arrow} and the
847 \l{#down-arrow-sub}{::down-arrow} Sub-control.
848 \br
849 \br
850 See \l{Qt Style Sheets Examples#Customizing QHeaderView}{Customizing QHeaderView}
851 for an example.
852
853 \row
854 \li QLabel \target qlabel-widget
855 \li Supports the \l{box model}. Does not support the
856 \l{#hover-ps}{:hover} pseudo-state.
857 \br
858 \br
859 Since 4.3, setting a stylesheet on a QLabel automatically
860 sets the QFrame::frameStyle property to QFrame::StyledPanel.
861 \br
862 \br
863 See \l{Qt Style Sheets Examples#Customizing QFrame}{Customizing QFrame} for an
864 example (a QLabel derives from QFrame).
865
866 \row
867 \li QLineEdit \target qlineedit-widget
868 \li Supports the \l{box model}.
869 \br
870 \br
871 The color and background of the selected item is styled using
872 \l{#selection-color-prop}{selection-color} and
873 \l{#selection-background-color-prop}{selection-background-color}
874 respectively.
875 \br
876 \br
877 The color of the placeholder text can be set using the
878 \l{#placeholder-text-color-prop}{placeholder-text-color} property.
879 \br
880 \br
881 The password character can be styled using the
882 \l{#lineedit-password-character-prop}{lineedit-password-character}
883 property.
884 \br
885 \br
886 The password mask delay can be changed using the
887 \l{#lineedit-password-mask-delay-prop}{lineedit-password-mask-delay}
888 \br
889 \br
890 See \l{Qt Style Sheets Examples#Customizing QLineEdit}{Customizing QLineEdit}
891 for an example.
892
893 \row
894 \li QListView \target qlistview-widget
895 \li Supports the \l{box model}.
896 \br
897 \br
898 When
899 \l{QAbstractItemView::alternatingRowColors}{alternating row colors}
900 is enabled, the alternating colors can be styled using the
901 \l{#alternate-background-color-prop}{alternate-background-color}
902 property.
903 \br
904 \br
905 The color and background of the selected item is styled using
906 \l{#selection-color-prop}{selection-color} and
907 \l{#selection-background-color-prop}{selection-background-color}
908 respectively.
909 \br
910 \br
911 The selection behavior is controlled by the
912 \l{#show-decoration-selected-prop}{show-decoration-selected} property.
913 \br
914 \br
915 Use the \l{#item-sub}{::item} subcontrol for more fine grained
916 control over the items in the QListView.
917 \br
918 \br
919 See \l{qabstractscrollarea-widget}{QAbstractScrollArea} to
920 style scrollable backgrounds.
921 \br
922 \br
923 See \l{Qt Style Sheets Examples#Customizing QListView}
924 {Customzing QListView} for an example.
925
926 \row
927 \li QListWidget \target qlistwidget-widget
928 \li See \l{#qlistview-widget}{QListView}.
929
930 \row
931 \li QMainWindow \target qmainwindow-widget
932 \li Supports styling of the separator.
933 \br
934 \br
935 The separator in a QMainWindow when using QDockWidget is styled
936 using the \l{#separator-sub}{::separator} subcontrol.
937 \br
938 \br
939 See \l{Qt Style Sheets Examples#Customizing QMainWindow}{Customizing QMainWindow}
940 for an example.
941
942 \row
943 \li QMenu \target qmenu-widget
944 \li Supports the \l{box model}.
945 \br
946 \br
947 Individual items are styled using the \l{#item-sub}{::item}
948 subcontrol. In addition to the usually supported pseudo states,
949 \c{item} subcontrol supports the
950 \l{#selected-ps}{:selected}, \l{#default-ps}{:default},
951 \l{#exclusive-ps}{:exclusive} and the
952 \l{#non-exclusive-ps}{non-exclusive} pseudo states.
953 \br
954 \br
955 The indicator of checkable menu items is styled using the
956 \l{#indicator-sub}{::indicator} subcontrol.
957 \br
958 \br
959 The separator is styled using the \l{#separator-sub}{::separator}
960 subcontrol.
961 \br
962 \br
963 For items with a sub menu, the arrow marks are styled using the
964 \l{right-arrow-sub}{right-arrow} and
965 \l{left-arrow-sub}{left-arrow}.
966 \br
967 \br
968 The scroller is styled using the \l{#scroller-sub}{::scroller}.
969 \br
970 \br
971 The tear-off is styled using the \l{#tearoff-sub}{::tearoff}.
972 \br
973 \br
974 See \l{Qt Style Sheets Examples#Customizing QMenu}{Customizing QMenu}
975 for an example.
976
977 \row
978 \li QMenuBar \target qmenubar-widget
979 \li Supports the \l{box model}.
980 \br
981 \br
982 The \l{#spacing-prop}{spacing}
983 property specifies the spacing between menu items.
984 Individual items are styled using the \l{#item-sub}{::item}
985 subcontrol.
986
987 \warning When running on Qt/Mac, the menu bar is usually embedded into the
988 system-wide menu bar. In this case, the style sheet will have no effect.
989
990 See \l{Qt Style Sheets Examples#Customizing QMenuBar}{Customizing QMenuBar}
991 for an example.
992
993 \row
994 \li QMessageBox \target qmessagebox-widget
995 \li The \l{#messagebox-text-interaction-flags-prop}
996 {messagebox-text-interaction-flags} property can be used to alter
997 the interaction with text in the message box.
998
999 \row
1000 \li QProgressBar \target qprogressbar-widget
1001 \li Supports the \l{box model}.
1002 \br
1003 \br
1004 The chunks of the progress bar
1005 can be styled using the \l{#chunk-sub}{::chunk} subcontrol.
1006 The chunk is displayed on the Contents rectangle of the widget.
1007 \br
1008 \br
1009 If the progress bar displays text, use the \l{text-align-prop}{text-align}
1010 property to position the text.
1011 \br
1012 \br
1013 Indeterminate progress bars have the
1014 \l{#indeterminate-ps}{:indeterminate} pseudo state set.
1015 \br
1016 \br
1017 See \l{Qt Style Sheets Examples#Customizing QProgressBar}{Customizing QProgressBar}
1018 for an example.
1019
1020 \row
1021 \li QPushButton \target qpushbutton-widget
1022 \li Supports the \l{box model}.
1023 \br
1024 \br
1025 Supports the \l{#default-ps}{:default},
1026 \l{#flat-ps}{:flat}, \l{#checked-ps}{:checked} pseudo states.
1027 \br
1028 \br
1029 Since 5.15, the \l{#icon-prop}{icon} property can be set to
1030 override the button icon.
1031 \br
1032 \br
1033 For QPushButton with a menu, the menu indicator is styled
1034 using the \l{#menu-indicator-sub}{::menu-indicator}
1035 subcontrol. Appearance of checkable push buttons can be
1036 customized using the \l{#open-ps}{:open} and
1037 \l{#closed-ps}{:closed} pseudo-states.
1038
1039 \warning If you only set a background-color on a QPushButton, the background
1040 may not appear unless you set the border property to some value. This is
1041 because, by default, the QPushButton draws a native border which completely
1042 overlaps the background-color. For example,
1043
1044 \snippet code/doc_src_stylesheet.qdoc 30
1045
1046 See \l{Qt Style Sheets Examples#Customizing QPushButton}{Customizing QPushButton}
1047 for an example.
1048
1049 \row
1050 \li QRadioButton \target qradiobutton-widget
1051 \li Supports the \l{box model}.
1052 \br
1053 \br
1054 The check indicator can be
1055 styled using the \l{#indicator-sub}{::indicator}
1056 subcontrol. By default, the indicator is placed in the Top
1057 Left corner of the Contents rectangle of the widget.
1058 \br
1059 \br
1060 The \l{#spacing-prop}{spacing} property
1061 specifies the spacing between the check indicator and
1062 the text.
1063 \br
1064 \br
1065 See \l{Qt Style Sheets Examples#Customizing QRadioButton}
1066 {Customizing QRadioButton} for an example.
1067
1068 \row
1069 \li QScrollBar \target qscrollbar-widget
1070 \li Supports the \l{box model}.
1071 \br
1072 \br
1073 The Contents rectangle of the widget
1074 is considered to be the groove over which the slider moves. The extent
1075 of the QScrollBar (i.e the width or the height depending on the orientation)
1076 is set using the \l{#width-prop}{width} or \l{#height-prop}{height} property
1077 respectively. To determine the orientation, use the
1078 \l{#horizontal-ps}{:horizontal} and the \l{vertical-ps}{:vertical}
1079 pseudo states.
1080 \br
1081 \br
1082 The slider can be styled using the \l{#handle-sub}{::handle} subcontrol.
1083 Setting the \l{#min-width-prop}{min-width} or \l{#min-height-prop}{min-height}
1084 provides size constraints for the slider depending on the orientation.
1085 \br
1086 \br
1087 The \l{add-line-sub}{::add-line} subcontrol can be used to style the
1088 button to add a line. By default, the add-line subcontrol is placed in
1089 top right corner of the Border rectangle of the widget. Depending on the
1090 orientation the \l{#right-arrow-sub}{::right-arrow} or
1091 \l{#down-arrow-sub}{::down-arrow}. By default, the arrows are placed in
1092 the center of the Contents rectangle of the add-line subcontrol.
1093 \br
1094 \br
1095 The \l{sub-line-sub}{::sub-line} subcontrol can be used to style the
1096 button to subtract a line. By default, the sub-line subcontrol is placed in
1097 bottom right corner of the Border rectangle of the widget. Depending on the
1098 orientation the \l{#left-arrow-sub}{::left-arrow} or
1099 \l{#up-arrow-sub}{::up-arrow}. By default, the arrows are placed in
1100 the center of the Contents rectangle of the sub-line subcontrol.
1101 \br
1102 \br
1103 The \l{sub-page-sub}{::sub-page} subcontrol can be used to style the
1104 region of the slider that subtracts a page. The \l{add-page-sub}{::add-page}
1105 subcontrol can be used to style the region of the slider that adds a page.
1106 \br
1107 \br
1108 See \l{Qt Style Sheets Examples#Customizing QScrollBar}{Customizing QScrollBar}
1109 for an example.
1110
1111 \row
1112 \li QSizeGrip \target qsizegrip-widget
1113 \li Supports the \l{#width-prop}{width},
1114 \l{#height-prop}{height}, and \l{#image-prop}{image}
1115 properties.
1116 \br
1117 \br
1118 See \l{Qt Style Sheets Examples#Customizing QSizeGrip}{Customizing QSizeGrip}
1119 for an example.
1120
1121 \row
1122 \li QSlider \target qslider-widget
1123 \li Supports the \l{box model}.
1124 \br
1125 \br
1126 For horizontal slides, the
1127 \l{min-width-prop}{min-width} and \l{height-prop}{height}
1128 properties must be provided. For vertical sliders, the
1129 \l{min-height-prop}{min-height} and \l{width-prop}{width}
1130 properties must be provided.
1131 \br
1132 \br
1133 The groove of the slider is styled
1134 using the \l{#groove-sub}{::groove}. The groove is
1135 positioned by default in the Contents rectangle of the widget.
1136 The thumb of the slider is styled using \l{#handle-sub}{::handle}
1137 subcontrol. The subcontrol moves in the Contents rectangle of
1138 the groove subcontrol.
1139 \br
1140 \br
1141 See \l{Qt Style Sheets Examples#Customizing QSlider}{Customizing QSlider}
1142 for an example.
1143
1144 \row
1145 \li QSpinBox \target qspinbox-widget
1146 \li The frame of the spin box can be styled using the \l{box
1147 model}.
1148 \br
1149 \br
1150 The up button and arrow can be styled using the
1151 \l{#up-button-sub}{::up-button} and
1152 \l{#up-arrow-sub}{::up-arrow} subcontrols. By default,
1153 the up-button is placed in the top right corner in the
1154 Padding rectangle of the widget. Without an explicit size,
1155 it occupies half the height of its reference rectangle.
1156 The up-arrow is placed in the center of the Contents
1157 rectangle of the up-button.
1158 \br
1159 \br
1160 The down button and arrow can be styled using the
1161 \l{#down-button-sub}{::down-button} and
1162 \l{#down-arrow-sub}{::down-arrow} subcontrols. By default,
1163 the down-button is placed in the bottom right corner in the
1164 Padding rectangle of the widget. Without an explicit size,
1165 it occupies half the height of its reference rectangle.
1166 The bottom-arrow is placed in the center of the Contents
1167 rectangle of the bottom-button.
1168 \br
1169 \br
1170 See \l{Qt Style Sheets Examples#Customizing QSpinBox}{Customizing QSpinBox}
1171 for an example.
1172
1173 \row
1174 \li QSplitter \target qsplitter-widget
1175 \li Supports the \l{box model}. The handle of the splitter
1176 is styled using the \l{#handle-sub}{::handle} subcontrol.
1177 \br
1178 \br
1179 See \l{Qt Style Sheets Examples#Customizing QSplitter}{Customizing QSplitter}
1180 for an example.
1181
1182 \row
1183 \li QStatusBar \target qstatusbar-widget
1184 \li Supports only the \l{Qt Style Sheets Reference#background-prop}
1185 {background} property.
1186 The frame for individual items can be style using the
1187 \l{#item-sub}{::item} subcontrol.
1188 \br
1189 \br
1190 See \l{Qt Style Sheets Examples#Customizing QStatusBar}{Customizing QStatusBar}
1191 for an example.
1192
1193 \row
1194 \li QTabBar \target qtabbar-widget
1195 \li Individual tabs may be styled using the \l{#tab-sub}{::tab} subcontrol.
1196 Close buttons using the \l{#close-button-sub}{::close-button}.
1197 The tabs support the
1198 \l{#only-one-ps}{:only-one}, \l{#first-ps}{:first},
1199 \l{#last-ps}{:last}, \l{#middle-ps}{:middle},
1200 \l{#previous-selected-ps}{:previous--selected},
1201 \l{#next-selected-ps}{:next-selected},
1202 \l{#selected-ps}{:selected} pseudo states.
1203 \br
1204 \br
1205 The \l{#top-ps}{:top}, \l{#left-ps}{:left}, \l{#right-ps}{:right},
1206 \l{#bottom-ps}{:bottom} pseudo states depending on the orientation
1207 of the tabs.
1208 \br
1209 \br
1210 Overlapping tabs for the selected state are created by using
1211 negative margins or using the \c{absolute} position scheme.
1212 \br
1213 \br
1214 The tear indicator of the QTabBar is styled using the
1215 \l{#tear-sub}{::tear} subcontrol.
1216 \br
1217 \br
1218 QTabBar used two QToolButtons for its scrollers that can be styled
1219 using the \c{QTabBar QToolButton} selector. To specify the width
1220 of the scroll button use the \l{#scroller-sub}{::scroller}
1221 subcontrol.
1222 \br
1223 \br
1224 The alignment of the tabs within the QTabBar is styled
1225 using the \l{#Alignment}{alignment} property.
1226 \br
1227 \warning
1228 To change the position of the QTabBar within a QTabWidget, use the
1229 \l{#tab-bar-sub}{tab-bar} subcontrol (and set subcontrol-position).
1230
1231 See \l{Qt Style Sheets Examples#Customizing QTabWidget and QTabBar}{Customizing QTabBar}
1232 for an example.
1233
1234 \row
1235 \li QTabWidget \target qtabwidget-widget
1236 \li The frame of the tab widget is styled using the
1237 \l{#pane-sub}{::pane} subcontrol. The left and right
1238 corners are styled using the \l{#left-corner-sub}{::left-corner}
1239 and \l{#right-corner-sub}{::right-corner} respectively.
1240 The position of the tab bar is controlled using the
1241 \l{#tab-bar-sub}{::tab-bar} subcontrol.
1242 \br
1243 \br
1244 By default, the subcontrols have positions of a QTabWidget in
1245 the QWindowsStyle. To place the QTabBar in the center, set the
1246 subcontrol-position of the tab-bar subcontrol.
1247 \br
1248 \br
1249 The \l{#top-ps}{:top}, \l{#left-ps}{:left}, \l{#right-ps}{:right},
1250 \l{#bottom-ps}{:bottom} pseudo states depending on the orientation
1251 of the tabs.
1252 \br
1253 \br
1254 See \l{Qt Style Sheets Examples#Customizing QTabWidget and QTabBar}
1255 {Customizing QTabWidget} for an example.
1256
1257 \row
1258 \li QTableView \target qtableview-widget
1259 \li Supports the \l{box model}. When
1260 \l{QAbstractItemView::alternatingRowColors}{alternating row colors}
1261 is enabled, the alternating colors can be styled using the
1262 \l{#alternate-background-color-prop}{alternate-background-color}
1263 property.
1264 \br
1265 \br
1266 The color and background of the selected item is styled using
1267 \l{#selection-color-prop}{selection-color} and
1268 \l{#selection-background-color-prop}{selection-background-color}
1269 respectively.
1270 \br
1271 \br
1272 The corner widget in a QTableView is implemented as a QAbstractButton
1273 and can be styled using the "QTableView QTableCornerButton::section"
1274 selector.
1275 \br
1276 \warning If you only set a background-color on a QTableCornerButton,
1277 the background may not appear unless you set the border property to
1278 some value. This is because, by default, the QTableCornerButton draws a
1279 native border which completely overlaps the background-color.
1280
1281 \br
1282 The color of the grid can be specified using the
1283 \l{#gridline-color-prop}{gridline-color} property.
1284 \br
1285 \br
1286 See \l{qabstractscrollarea-widget}{QAbstractScrollArea} to
1287 style scrollable backgrounds.
1288 \br
1289 \br
1290 See \l{Qt Style Sheets Examples#Customizing QTableView}
1291 {Customzing QTableView} for an example.
1292
1293 \row
1294 \li QTableWidget \target qtablewidget-widget
1295 \li See \l{#qtableview-widget}{QTableView}.
1296
1297 \row
1298 \li QTextEdit \target qtextedit-widget
1299 \li Supports the \l{box model}.
1300 \br
1301 \br
1302 The color and background of selected text is styled using
1303 \l{#selection-color-prop}{selection-color} and
1304 \l{#selection-background-color-prop}{selection-background-color}
1305 respectively.
1306 \br
1307 \br
1308 The color of the placeholder text can be set using the
1309 \l{#placeholder-text-color-prop}{placeholder-text-color} property.
1310 \br
1311 \br
1312 See \l{qabstractscrollarea-widget}{QAbstractScrollArea} to
1313 style scrollable backgrounds.
1314
1315 \row
1316 \li QTimeEdit \target qtimeedit-widget
1317 \li See \l{#qspinbox-widget}{QSpinBox}.
1318
1319 \row
1320 \li QToolBar \target qtoolbar-widget
1321 \li Supports the \l{box model}.
1322 \br
1323 \br
1324 The \l{#top-ps}{:top}, \l{#left-ps}{:left}, \l{#right-ps}{:right},
1325 \l{#bottom-ps}{:bottom} pseudo states depending on the area in
1326 which the tool bar is grouped.
1327 \br
1328 \br
1329 The \l{#first-ps}{:first}, \l{#last-ps}{:last}, \l{#middle-ps}{:middle},
1330 \l{#only-one-ps}{:only-one} pseudo states indicator the position
1331 of the tool bar within a line group (See
1332 QStyleOptionToolBar::positionWithinLine).
1333 \br
1334 \br
1335 The separator of a QToolBar is styled using the
1336 \l{#separator-sub}{::separator} subcontrol.
1337 \br
1338 \br
1339 The handle (to move the toolbar) is styled using the
1340 \l{#handle-sub}{::handle} subcontrol.
1341 \br
1342 \br
1343 See \l{Qt Style Sheets Examples#Customizing QToolBar}{Customizing QToolBar}
1344 for an example.
1345
1346 \row
1347 \li QToolBox \target qtoolbox-widget
1348 \li Supports the \l{box model}.
1349 \br
1350 \br
1351 The individual tabs can by styled using the
1352 \l{#tab-sub}{::tab} subcontrol. The tabs support the
1353 \l{#only-one-ps}{:only-one}, \l{#first-ps}{:first},
1354 \l{#last-ps}{:last}, \l{#middle-ps}{:middle},
1355 \l{#previous-selected-ps}{:previous-selected},
1356 \l{#next-selected-ps}{:next-selected},
1357 \l{#selected-ps}{:selected} pseudo states.
1358
1359 \row
1360 \li QToolButton \target qtoolbutton-widget
1361 \li Supports the \l{box model}.
1362 \br
1363 \br
1364 If the QToolButton has a menu, is
1365 \l{#menu-indicator-sub}{::menu-indicator} subcontrol can be used to
1366 style the indicator. By default, the menu-indicator is positioned
1367 at the bottom right of the Padding rectangle of the widget.
1368 \br
1369 \br
1370 If the QToolButton is in QToolButton::MenuButtonPopup mode,
1371 the \l{#menu-button-sub}{::menu-button} subcontrol is used to draw the
1372 menu button. \l{#menu-arrow-sub}{::menu-arrow} subcontrol is used to
1373 draw the menu arrow inside the menu-button. By default, it is
1374 positioned in the center of the Contents rectangle of the
1375 menu-button subcontrol.
1376 \br
1377 \br
1378 When the QToolButton displays arrows, the \l{#up-arrow-sub}{::up-arrow},
1379 \l{#down-arrow-sub}{::down-arrow}, \l{#left-arrow-sub}{::left-arrow}
1380 and \l{#right-arrow-sub}{::right-arrow} subcontrols are used.
1381 \br
1382 \warning If you only set a background-color on a QToolButton, the background
1383 will not appear unless you set the border property to some value. This is
1384 because, by default, the QToolButton draws a native border which completely
1385 overlaps the background-color. For example,
1386
1387 \snippet code/doc_src_stylesheet.qdoc 31
1388
1389 See \l{Qt Style Sheets Examples#Customizing QToolButton}{Customizing QToolButton}
1390 for an example.
1391
1392 \row
1393 \li QToolTip \target qtooltip-widget
1394 \li Supports the \l{box model}. The \l{#opacity-prop}{opacity}
1395 property controls the opacity of the tooltip.
1396 \br
1397 \br
1398 See \l{Qt Style Sheets Examples#Customizing QFrame}{Customizing QFrame}
1399 for an example (a QToolTip is a QFrame).
1400
1401 \row
1402 \li QTreeView \target qtreeview-widget
1403 \li Supports the \l{box model}. When
1404 \l{QAbstractItemView::alternatingRowColors}{alternating row colors}
1405 is enabled, the alternating colors can be styled using the
1406 \l{#alternate-background-color-prop}{alternate-background-color}
1407 property.
1408 \br
1409 \br
1410 The color and background of the selected item is styled using
1411 \l{#selection-color-prop}{selection-color} and
1412 \l{#selection-background-color-prop}{selection-background-color}
1413 respectively.
1414 \br
1415 \br
1416 The selection behavior is controlled by the
1417 \l{#show-decoration-selected-prop}{show-decoration-selected} property.
1418 \br
1419 \br
1420 The branches of the tree view can be styled using the
1421 \l{#branch-sub}{::branch} subcontrol. The
1422 ::branch Sub-control supports the \l{open-ps}{:open},
1423 \l{closed-ps}{:closed}, \l{has-siblings-ps}{:has-sibling} and
1424 \l{has-children-ps}{:has-children} pseudo states.
1425 \br
1426 \br
1427 Use the \l{#item-sub}{::item} subcontrol for more fine grained
1428 control over the items in the QTreeView.
1429 \br
1430 \br
1431 See \l{qabstractscrollarea-widget}{QAbstractScrollArea} to
1432 style scrollable backgrounds.
1433 \br
1434 \br
1435 See \l{Qt Style Sheets Examples#Customizing QTreeView}{Customizing QTreeView}
1436 for an example to style the branches.
1437
1438 \row
1439 \li QTreeWidget \target qtreewidget-widget
1440 \li See \l{#qtreeview-widget}{QTreeView}.
1441
1442 \row
1443 \li QWidget \target qwidget-widget
1444 \li Supports only the \l{Qt Style Sheets Reference#background-prop}{background},
1445 \l{#background-clip-prop}{background-clip} and
1446 \l{#background-origin-prop}{background-origin} properties.
1447 \br
1448 \br
1449 If you subclass from QWidget, you need to provide a paintEvent for your
1450 custom QWidget as below:
1451 \snippet code/doc_src_stylesheet.cpp 32
1452
1453 The above code is a no-operation if there is no stylesheet set.
1454
1455 \warning Make sure you define the Q_OBJECT macro for your custom
1456 widget.
1457
1458 \endtable
1459
1460 \section1 List of Properties
1461
1462 This section lists all the properties supported by Qt Style
1463 Sheets. Which values can be given to a property depend on the
1464 \l{List of Property Types}{property's type}. Unless otherwise
1465 specified, the following properties apply to all widgets. Properties
1466 marked with an asterisk * are specific to Qt and have no equivalent
1467 in CSS2 or CSS3. The Qt-specific properties are the following:
1468 \list
1469 \li \l{#gridline-color*}{gridline-color*}
1470 \li \l{#image*}{image*}
1471 \li \l{#lineedit-password-character*}{lineedit-password-character*}
1472 \li \l{#lineedit-password-mask-delay*}{lineedit-password-mask-delay*}
1473 \li \l{#messagebox-text-interaction-flags*}{messagebox-text-interaction-flags*}
1474 \li \l{#opacity*}{opacity*}
1475 \li \l{#placeholder-text-color*}{placeholder-text-color*}
1476 \li \l{#selection-background-color*}{selection-background-color*}
1477 \li \l{#selection-color*}{selection-color*}
1478 \li \l{#show-decoration-selected*}{show-decoration-selected*}
1479 \li \l{#spacing*}{spacing*}
1480 \li \l{#subcontrol-origin*}{subcontrol-origin*}
1481 \li \l{#subcontrol-position*}{subcontrol-position*}
1482 \li \l{#widget-animation-duration*}{widget-animation-duration*}
1483 \endlist
1484
1485 \section2 accent-color
1486
1487 \table
1488 \row \li \b Type \li \l{#Brush}{Brush}
1489 \endtable
1490
1491 The property sets the \c Accent, which is used to emphasize
1492 interactive UI elements. If this property is not set, it defaults to the \c highlight color.
1493
1494 \section2 alternate-background-color
1495 \target alternate-background-color-prop
1496 \table
1497 \row \li \b Type \li \l{#Brush}{Brush}
1498 \endtable
1499 The \l{QAbstractItemView::alternatingRowColors}
1500 {alternate background color} used in QAbstractItemView subclasses.
1501
1502 If this property is not set, the default value is
1503 whatever is set for the palette's
1504 \l{QPalette::}{AlternateBase} role.
1505
1506 Example:
1507
1508 \snippet code/doc_src_stylesheet.qdoc 33
1509
1510 See also \l{Qt Style Sheets Reference#background-prop}{background} and
1511 \l{#selection-background-color-prop}{selection-background-color}.
1512
1513 \section2 background
1514 \target background-prop
1515 \table
1516 \row \li \b Type \li \l{#Background}{Background}
1517 \endtable
1518 Shorthand notation for setting the background. Equivalent
1519 to specifying \c background-color, \c background-image, \c
1520 background-repeat, and/or \c background-position.
1521
1522 This property is supported by QAbstractItemView
1523 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1524 QComboBox, QDialog, QFrame, QGroupBox, QLabel, QLineEdit,
1525 QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter,
1526 QTextEdit, QToolTip, and plain \l{QWidget}s.
1527
1528 Example:
1529
1530 \snippet code/doc_src_stylesheet.qdoc 34
1531
1532
1533 Often, it is required to set a fill pattern similar to the styles
1534 in Qt::BrushStyle. You can use the background-color property for
1535 Qt::SolidPattern, Qt::RadialGradientPattern, Qt::LinearGradientPattern
1536 and Qt::ConicalGradientPattern. The other patterns are easily achieved
1537 by creating a background image that contains the pattern.
1538
1539 Example:
1540
1541 \snippet code/doc_src_stylesheet.qdoc 35
1542
1543 See also \l{#background-origin-prop}{background-origin},
1544 \l{#selection-background-color-prop}{selection-background-color},
1545 \l{#background-clip-prop}{background-clip},
1546 \l{#background-attachment-prop}{background-attachment}
1547 and \l{#alternate-background-color-prop}{alternate-background-color}.
1548
1549 \section2 background-color
1550 \target background-color-prop
1551 \table
1552 \row \li \b Type \li \l{#Brush}{Brush}
1553 \endtable
1554 The background color used for the widget.
1555
1556 Examples:
1557
1558 \snippet code/doc_src_stylesheet.qdoc 36
1559
1560 \section2 background-image
1561 \target background-image-prop
1562 \table
1563 \row \li \b Type \li \l{#Url}{Url}
1564 \endtable
1565 The background image used for the widget. Semi-transparent
1566 parts of the image let the \c background-color shine
1567 through.
1568
1569 Example:
1570
1571 \snippet code/doc_src_stylesheet.qdoc 37
1572
1573
1574 \section2 background-repeat
1575 \target background-repeat-prop
1576 \table
1577 \row \li \b Type \li \l{#Repeat}{Repeat}
1578 \endtable
1579 Whether and how the background image is repeated to fill
1580 the \c background-origin rectangle.
1581
1582 If this property is not specified, the background image
1583 is repeated in both directions (\c repeat).
1584
1585 Example:
1586
1587 \snippet code/doc_src_stylesheet.qdoc 38
1588
1589 \section2 background-position
1590 \table
1591 \row \li \b Type \li \l{#Alignment}{Alignment}
1592 \endtable
1593 The alignment of the background image within the \c
1594 background-origin rectangle.
1595
1596 If this property is not specified, the alignment is \c
1597 top \c left.
1598
1599 Example:
1600
1601 \snippet code/doc_src_stylesheet.qdoc 39
1602
1603 \section2 background-attachment
1604 \target background-attachment-prop
1605 \table
1606 \row \li \b Type \li \l{#Attachment}{Attachment}
1607 \endtable
1608 Determines whether the background-image in a QAbstractScrollArea
1609 is scrolled or fixed with respect to the viewport.
1610 By default, the background-image scrolls with the viewport.
1611
1612 Example:
1613
1614 \snippet code/doc_src_stylesheet.qdoc 40
1615
1616 See also \l{Qt Style Sheets Reference#background-prop}{background}
1617
1618 \section2 background-clip
1619 \target background-clip-prop
1620 \table
1621 \row \li \b Type \li \l{#Origin}{Origin}
1622 \endtable
1623 The widget's rectangle, in which the \c background is drawn.
1624
1625 This property specifies the rectangle to which the \c background-color
1626 and \c background-image are clipped.
1627
1628 This property is supported by QAbstractItemView
1629 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1630 QComboBox, QDialog, QFrame, QGroupBox, QLabel,
1631 QPushButton, QRadioButton, QSplitter, QTextEdit, QToolTip,
1632 and plain \l{QWidget}s.
1633
1634 If this property is not specified, the default is \c
1635 border.
1636
1637 Example:
1638
1639 \snippet code/doc_src_stylesheet.qdoc 41
1640
1641 See also \l{Qt Style Sheets Reference#background-prop}{background},
1642 \l{#background-origin-prop}{background-origin} and \l{The Box Model}.
1643
1644 \section2 background-origin
1645 \target background-origin-prop
1646 \table
1647 \row \li \b Type \li \l{#Origin}{Origin}
1648 \endtable
1649
1650 The widget's background rectangle, to use in conjunction
1651 with \c background-position and \c background-image.
1652
1653 This property is supported by QAbstractItemView
1654 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1655 QComboBox, QDialog, QFrame, QGroupBox, QLabel,
1656 QPushButton, QRadioButton, QSplitter, QTextEdit, QToolTip,
1657 and plain \l{QWidget}s.
1658
1659 If this property is not specified, the default is \c
1660 padding.
1661
1662 Example:
1663
1664 \snippet code/doc_src_stylesheet.qdoc 42
1665
1666 See also \l{Qt Style Sheets Reference#background-prop}{background} and
1667 \l{The Box Model}.
1668
1669 \section2 border
1670 \target border-prop
1671 \table
1672 \row \li \b Type \li \l{#Border}{Border}
1673 \endtable
1674
1675 Shorthand notation for setting the widget's border. Equivalent
1676 to specifying \c border-color, \c border-style, and/or
1677 \c border-width.
1678
1679 This property is supported by QAbstractItemView
1680 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1681 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit,
1682 QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter,
1683 QTextEdit, QToolTip, and plain \l{QWidget}s.
1684
1685 Example:
1686
1687 \snippet code/doc_src_stylesheet.qdoc 43
1688
1689 \section2 border-top
1690
1691 \table
1692 \row \li \b Type \li \l{#Border}{Border}
1693 \endtable
1694
1695 Shorthand notation for setting the widget's top border.
1696 Equivalent to specifying \c border-top-color, \c
1697 border-top-style, and/or \c border-top-width.
1698
1699 \section2 border-right
1700 \table
1701 \row \li \b Type \li \l{#Border}{Border}
1702 \endtable
1703
1704 Shorthand notation for setting the widget's right border.
1705 Equivalent to specifying \c border-right-color, \c
1706 border-right-style, and/or \c border-right-width.
1707
1708 \section2 border-bottom
1709 \table
1710 \row \li \b Type \li \l{#Border}{Border}
1711 \endtable
1712
1713 Shorthand notation for setting the widget's bottom border.
1714 Equivalent to specifying \c border-bottom-color, \c
1715 border-bottom-style, and/or \c border-bottom-width.
1716
1717 \section2 border-left
1718 \table
1719 \row \li \b Type \li \l{#Border}{Border}
1720 \endtable
1721
1722 Shorthand notation for setting the widget's left border.
1723 Equivalent to specifying \c border-left-color, \c
1724 border-left-style, and/or \c border-left-width.
1725
1726
1727 \section2 border-color
1728 \target border-attrs
1729 \target border-color-prop
1730 \table
1731 \row \li \b Type \li \l{#Box Colors}{Box Colors}
1732 \endtable
1733
1734 The color of all the border's edges. Equivalent to
1735 specifying \c border-top-color, \c border-right-color, \c
1736 border-bottom-color, and \c border-left-color.
1737
1738 This property is supported by QAbstractItemView
1739 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1740 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit,
1741 QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter,
1742 QTextEdit, QToolTip, and plain \l{QWidget}s.
1743
1744 If this property is not specified, it defaults to
1745 \l{#color-prop}{color} (i.e., the widget's foreground
1746 color).
1747
1748 Example:
1749
1750 \snippet code/doc_src_stylesheet.qdoc 44
1751
1752 See also \l{Qt Style Sheets Reference#border-style-prop}{border-style},
1753 \l{Qt Style Sheets Reference#border-width-prop}{border-width},
1754 \l{#border-image-prop}{border-image}, and \l{The Box Model}.
1755
1756 \section2 border-top-color
1757 \table
1758 \row \li \b Type \li \l{#Brush}{Brush}
1759 \endtable
1760
1761 The color of the border's top edge.
1762
1763 \section2 border-right-color
1764 \table
1765 \row \li \b Type \li \l{#Brush}{Brush}
1766 \endtable
1767
1768 The color of the border's right edge.
1769
1770 \section2 border-bottom-color
1771 \table
1772 \row \li \b Type \li \l{#Brush}{Brush}
1773 \endtable
1774
1775 The color of the border's bottom edge.
1776
1777 \section2 border-left-color
1778 \table
1779 \row \li \b Type \li \l{#Brush}{Brush}
1780 \endtable
1781
1782 The color of the border's left edge.
1783
1784 \section2 border-image
1785 \target border-image-prop
1786 \table
1787 \row \li \b Type \li \l{#Border Image}{Border Image}
1788 \endtable
1789
1790 The image used to fill the border. The image is cut into
1791 nine parts and stretched appropriately if necessary. See
1792 \l{#Border Image}{Border Image} for details.
1793
1794 This property is supported by QAbstractItemView
1795 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1796 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit,
1797 QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter,
1798 QTextEdit and QToolTip.
1799
1800 See also \l{#border-color-prop}{border-color},
1801 \l{Qt Style Sheets Reference#border-style-prop}{border-style},
1802 \l{Qt Style Sheets Reference#border-width-prop}{border-width}, and
1803 \l{The Box Model}.
1804
1805 \section2 border-radius
1806 \target border-radius-prop
1807 \table
1808 \row \li \b Type \li \l{#Radius}{Radius}
1809 \endtable
1810
1811 The radius of the border's corners. Equivalent to
1812 specifying \c border-top-left-radius, \c
1813 border-top-right-radius, \c border-bottom-right-radius,
1814 and \c border-bottom-left-radius.
1815
1816 The border-radius clips the element's
1817 \l{Qt Style Sheets Reference#background-prop}{background}.
1818
1819 This property is supported by QAbstractItemView
1820 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1821 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
1822 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
1823 and QToolTip.
1824
1825 If this property is not specified, it defaults to 0.
1826
1827 Example:
1828
1829 \snippet code/doc_src_stylesheet.qdoc 45
1830
1831 See also \l{Qt Style Sheets Reference#border-width-prop}{border-width} and
1832 \l{The Box Model}.
1833
1834 \section2 border-top-left-radius
1835 \table
1836 \row \li \b Type \li \l{#Radius}{Radius}
1837 \endtable
1838
1839 The radius of the border's top-left corner.
1840
1841 \section2 border-top-right-radius
1842 \table
1843 \row \li \b Type \li \l{#Radius}{Radius}
1844 \endtable
1845
1846 The radius of the border's top-right corner.
1847
1848 \section2 border-bottom-right-radius
1849 \table
1850 \row \li \b Type \li \l{#Radius}{Radius}
1851 \endtable
1852
1853 The radius of the border's bottom-right corner. Setting
1854 this property to a positive value results in a rounded
1855 corner.
1856
1857 \section2 border-bottom-left-radius
1858 \table
1859 \row \li \b Type \li \l{#Radius}{Radius}
1860 \endtable
1861
1862 The radius of the border's bottom-left corner. Setting this
1863 property to a positive value results in a rounded corner.
1864
1865 \section2 border-style
1866 \target border-style-prop
1867 \table
1868 \row \li \b Type \li \l{#Border Style}{Border Style}
1869 \endtable
1870
1871 The style of all the border's edges.
1872
1873 This property is supported by QAbstractItemView
1874 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1875 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
1876 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
1877 and QToolTip.
1878
1879 If this property is not specified, it defaults to \c none.
1880
1881 Example:
1882
1883 \snippet code/doc_src_stylesheet.qdoc 46
1884
1885 See also \l{#border-color-prop}{border-color},
1886 \l{Qt Style Sheets Reference#border-style-prop}{border-style},
1887 \l{#border-image-prop}{border-image}, and \l{The Box Model}.
1888
1889 \section2 border-top-style
1890 \table
1891 \row \li \b Type \li \l{#Border Style}{Border Style}}
1892 \endtable
1893
1894 The style of the border's top edge.
1895
1896 \section2 border-right-style
1897 \table
1898 \row \li \b Type \li \l{#Border Style}{Border Style}
1899 \endtable
1900
1901 The style of the border's right edge.
1902
1903 \section2 border-bottom-style
1904 \table
1905 \row \li \b Type \li \l{#Border Style}{Border Style}
1906 \endtable
1907
1908 The style of the border's bottom edge.
1909
1910 \section2 border-left-style
1911 \table
1912 \row \li \b Type \li \l{#Border Style}{Border Style}
1913 \endtable
1914
1915 The style of the border's left edge.
1916
1917 \section2 border-width
1918 \target border-width-prop
1919 \table
1920 \row \li \b Type \li \l{#Box Lengths}{Box Lengths}
1921 \endtable
1922
1923 The width of the border. Equivalent to setting \c
1924 border-top-width, \c border-right-width, \c
1925 border-bottom-width, and \c border-left-width.
1926
1927 This property is supported by QAbstractItemView
1928 subclasses, QAbstractSpinBox subclasses, QCheckBox,
1929 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
1930 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
1931 and QToolTip.
1932
1933 Example:
1934
1935 \snippet code/doc_src_stylesheet.qdoc 47
1936
1937 See also \l{#border-color-prop}{border-color},
1938 \l{#border-radius-prop}{border-radius},
1939 \l{Qt Style Sheets Reference#border-style-prop}{border-style},
1940 \l{#border-image-prop}{border-image}, and
1941 \l{The Box Model}.
1942
1943 \section2 border-top-width
1944 \table
1945 \row \li \b Type \li \l{#Length}{Length}
1946 \endtable
1947
1948 The width of the border's top edge.
1949
1950 \section2 border-right-width
1951 \table
1952 \row \li \b Type \li \l{#Length}{Length}
1953 \endtable
1954
1955 The width of the border's right edge.
1956
1957 \section2 border-bottom-width
1958 \table
1959 \row \li \b Type \li \l{#Length}{Length}
1960 \endtable
1961
1962 The width of the border's bottom edge.
1963
1964 \section2 border-left-width
1965 \table
1966 \row \li \b Type \li \l{#Length}{Length}
1967 \endtable
1968
1969 The width of the border's left edge.
1970
1971 \section2 bottom
1972 \target bottom-prop
1973 \table
1974 \row \li \b Type \li \l{#Length}{Length}
1975 \endtable
1976
1977 If \l{#position-prop}{position} is \c relative (the
1978 default), moves a subcontrol by a certain offset up;
1979 specifying \tt{bottom: \e{y}} is then equivalent to
1980 specifying \tt{\l{Qt Style Sheets Reference#top-prop}{top}: -\e{y}}.
1981
1982 If \l{#position-prop}{position} is \c absolute, the \c
1983 bottom property specifies the subcontrol's bottom edge
1984 in relation to the parent's bottom edge (see also
1985 \l{Qt Style Sheets Reference#subcontrol-origin-prop}
1986 {subcontrol-origin}).
1987
1988 Example:
1989
1990 \snippet code/doc_src_stylesheet.qdoc 48
1991
1992 See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{#right-prop}{right}, and
1993 \l{Qt Style Sheets Reference#top-prop}{top}.
1994
1995
1996 \section2 button-layout
1997 \target button-layout-prop
1998 \table
1999 \row \li \b Type \li \l{#Number}{Number}
2000 \endtable
2001
2002 The layout of buttons in a QDialogButtonBox or
2003 a QMessageBox. The possible values are 0
2004 (\l{QDialogButtonBox::}{WinLayout}), 1
2005 (\l{QDialogButtonBox::}{MacLayout}), 2
2006 (\l{QDialogButtonBox::}{KdeLayout}), 3
2007 (\l{QDialogButtonBox::}{GnomeLayout}) and 5
2008 (\l{QDialogButtonBox::}{AndroidLayout}).
2009
2010 If this property is not specified, it defaults to the
2011 value specified by the current style for the
2012 \l{QStyle::}{SH_DialogButtonLayout} style hint.
2013
2014 Example:
2015
2016 \snippet code/doc_src_stylesheet.qdoc 49
2017
2018
2019 \section2 color
2020 \target color-prop
2021 \table
2022 \row \li \b Type \li \l{#Brush}{Brush} \br
2023 \endtable
2024
2025 The color used to render text.
2026
2027 This property is supported by all widgets that respect
2028 the \l QWidget::palette.
2029
2030 If this property is not set, the default is whatever is
2031 set for in the widget's palette for the
2032 QWidget::foregroundRole (typically black).
2033
2034 Example:
2035
2036 \snippet code/doc_src_stylesheet.qdoc 50
2037
2038 See also \l{Qt Style Sheets Reference#background-prop}{background} and
2039 \l{#selection-color-prop}{selection-color}.
2040
2041 \section2 dialogbuttonbox-buttons-have-icons
2042 \table
2043 \row \li \b Type \li \l{#Boolean}{Boolean}
2044 \endtable
2045
2046 Whether the buttons in a QDialogButtonBox show icons
2047
2048 If this property is set to 1, the buttons of a QDialogButtonBox
2049 show icons; if it is set to 0, the icons are not shown.
2050
2051 See the \l{Qt Style Sheets Reference#list of icons}{List of Icons}
2052 section for information on how to set icons.
2053
2054 \snippet code/doc_src_stylesheet.qdoc 51
2055
2056 \note Styles defining this property must be applied before the
2057 QDialogButtonBox is created; this means that you must apply the
2058 style to the parent widget or to the application itself.
2059
2060 \omit
2061 \row
2062 \li \b{\c etch-disabled-text}*
2063 \li \l{#Boolean}{Boolean}
2064 \li Whether disabled text is drawn etched.
2065
2066 If this property is not specified, it defaults to the
2067 value specified by the current style for the
2068 \l{QStyle::}{SH_EtchDisabledText} style hint.
2069
2070 Example:
2071
2072 \snippet code/doc_src_stylesheet.qdoc 52
2073 \endomit
2074
2075 \section2 font
2076 \target font-prop
2077 \table
2078 \row \li \b Type \li \l{#Font}{Font}
2079 \endtable
2080
2081 Shorthand notation for setting the text's font. Equivalent
2082 to specifying \c font-family, \c font-size, \c font-style,
2083 and/or \c font-weight.
2084
2085 This property is supported by all widgets that respect
2086 the \l QWidget::font.
2087
2088 If this property is not set, the default is the
2089 QWidget::font.
2090
2091 Example:
2092
2093 \snippet code/doc_src_stylesheet.qdoc 53
2094
2095 \section2 font-family
2096 \table
2097 \row \li \b Type \li String
2098 \endtable
2099
2100 The font family.
2101
2102 Example:
2103
2104 \snippet code/doc_src_stylesheet.qdoc 54
2105
2106 \section2 font-size
2107 \table
2108 \row \li \b Type \li \l{#Font Size}{Font Size}
2109 \endtable
2110
2111 The font size. In this version of Qt, only pt and px metrics are
2112 supported.
2113
2114 Example:
2115
2116 \snippet code/doc_src_stylesheet.qdoc 55
2117
2118 \section2 font-style
2119 \table
2120 \row \li \b Type \li \l {#Font Style} {Font Style}
2121 \endtable
2122
2123 The font style.
2124
2125 Example:
2126
2127 \snippet code/doc_src_stylesheet.qdoc 56
2128
2129 \section2 font-weight
2130 \table
2131 \row \li \b Type \li \l{#Font Weight}{Font Weight}
2132 \endtable
2133
2134 The weight of the font.
2135
2136 \section2 gridline-color*
2137 \target gridline-color-prop
2138 \table
2139 \row \li \b Type \li \l{#Color}{Color}
2140 \endtable
2141
2142 The color of the grid line in a QTableView.
2143
2144 If this property is not specified, it defaults to the
2145 value specified by the current style for the
2146 \l{QStyle::}{SH_Table_GridLineColor} style hint.
2147
2148 Example:
2149
2150 \snippet code/doc_src_stylesheet.qdoc 57
2151
2152
2153 \section2 height
2154 \target height-prop
2155 \table
2156 \row \li \b Type \li \l{#Length}{Length}
2157 \endtable
2158
2159 The height of a subcontrol (or in some case, a widget).
2160
2161 If this property is not specified, it defaults to a value
2162 that depends on the subcontrol/widget and on the current style.
2163
2164 \warning Unless otherwise specified, this property has no effect
2165 when set on widgets. If you want a widget with a fixed height, set
2166 the \l{#min-width-prop}{min-height} and
2167 \l{#max-width-prop}{max-height} to the same value.
2168
2169 Example:
2170
2171 \snippet code/doc_src_stylesheet.qdoc 58
2172
2173 See also \l{#width-prop}{width}.
2174
2175 \section2 icon
2176 \target icon-prop
2177 \table
2178 \row \li \b Type \li \l{#Url}{Url}+
2179 \endtable
2180
2181 The icon that is used, for widgets that have an icon.
2182
2183 The only widget currently supporting this property is QPushButton.
2184
2185 \note It's the application's responsibility to assign an icon to a
2186 button (using the QAbstractButton API), and not the style's. So be
2187 careful setting it unless your stylesheet is targeting a specific
2188 application.
2189
2190 Available since 5.15.
2191
2192 \section2 icon-size
2193 \target icon-size-prop
2194 \table
2195 \row \li \b Type \li \l{#Length}{Length}
2196 \endtable
2197
2198 The width and height of the icon in a widget.
2199
2200 The icon size of the following widgets can be set using this
2201 property.
2202 \list
2203 \li QCheckBox
2204 \li QListView
2205 \li QPushButton
2206 \li QRadioButton
2207 \li QTabBar
2208 \li QToolBar
2209 \li QToolBox
2210 \li QTreeView
2211 \endlist
2212
2213 \section2 image*
2214 \target image-prop
2215 \table
2216 \row \li \b Type \li \l{#Url}{Url}+
2217 \endtable
2218
2219 The image that is drawn in the contents rectangle of a
2220 subcontrol.
2221
2222 The image property accepts a list of \l{#Url}{Url}s or
2223 a \c{svg}. The actual image that is drawn is determined
2224 using the same algorithm as QIcon (i.e) the image is never scaled
2225 up but always scaled down if necessary. If a \c{svg} is specified,
2226 the image is scaled to the size of the contents rectangle.
2227 Setting the size of a \c{svg} can be done with the
2228 \l{#width-prop}{width} and \l{#height-prop}{height} property
2229 (supported since Qt 6.13)
2230
2231 Setting the image property on sub controls implicitly sets the
2232 width and height of the sub-control (unless the image in a SVG).
2233
2234 In Qt 4.3 and later, the alignment of the
2235 image within the rectangle can be specified using
2236 \l{image-position-prop}{image-position}.
2237
2238 This property is for subcontrols only--we don't support it for
2239 other elements.
2240
2241 \warning The QIcon SVG plugin is needed to render SVG images.
2242
2243 Example:
2244
2245 \snippet code/doc_src_stylesheet.qdoc 59
2246
2247
2248 \section2 image-position
2249 \target image-position-prop
2250 \table
2251 \row \li \b Type \li \l{#Alignment}{alignment}
2252 \endtable
2253
2254 In Qt 4.3 and later, the alignment of the image image's position can be specified
2255 using relative or absolute position.
2256
2257 \section2 left
2258 \target left-prop
2259 \table
2260 \row \li \b Type \li \l{#Length}{Length}
2261 \endtable
2262
2263 If \l{#position-prop}{position} is \c relative (the
2264 default), moves a subcontrol by a certain offset to
2265 the right.
2266
2267 If \l{#position-prop}{position} is \c absolute, the \c
2268 left property specifies the subcontrol's left edge in
2269 relation to the parent's left edge (see also
2270 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}).
2271
2272 If this property is not specified, it defaults to \c 0.
2273
2274 Example:
2275
2276 \snippet code/doc_src_stylesheet.qdoc 60
2277
2278 See also \l{#right-prop}{right}, \l{Qt Style Sheets Reference#top-prop}{top}, and
2279 \l{#bottom-prop}{bottom}.
2280
2281 \section2 letter-spacing
2282 \table
2283 \row \li \b Type \li \l{#Length}{Length}
2284 \endtable
2285
2286 Space between characters in a string within a widget.
2287
2288 \section2 lineedit-password-character*
2289 \target lineedit-password-character-prop
2290 \table
2291 \row \li \b Type \li \l{#Number}{Number}
2292 \endtable
2293
2294 The QLineEdit password character as a Unicode number.
2295
2296 If this property is not specified, it defaults to the
2297 value specified by the current style for the
2298 \l{QStyle::}{SH_LineEdit_PasswordCharacter} style hint.
2299
2300 Example:
2301
2302 \snippet code/doc_src_stylesheet.qdoc 61
2303
2304
2305 \section2 lineedit-password-mask-delay*
2306 \target lineedit-password-mask-delay-prop
2307 \table
2308 \row \li \b Type \li \l{#Number}{Number}
2309 \endtable
2310
2311 The QLineEdit password mask delay in milliseconds before
2312 \l{#lineedit-password-character-prop}{lineedit-password-character} is applied to visible character.
2313
2314 If this property is not specified, it defaults to the
2315 value specified by the current style for the
2316 \l{QStyle::}{SH_LineEdit_PasswordMaskDelay} style hint.
2317
2318 Available since Qt 5.4.
2319
2320 Example:
2321
2322 \snippet code/doc_src_stylesheet.qdoc 160
2323
2324 \section2 margin
2325 \target margin-prop
2326 \table
2327 \row \li \b Type \li \l {#Box Lengths}{Box Lengths}
2328 \endtable
2329
2330 The widget's margins. Equivalent to specifying \c
2331 margin-top, \c margin-right, \c margin-bottom, and \c
2332 margin-left.
2333
2334 This property is supported by QAbstractItemView
2335 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2336 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2337 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
2338 and QToolTip.
2339
2340 If this property is not specified, it defaults to \c 0.
2341
2342 Example:
2343
2344 \snippet code/doc_src_stylesheet.qdoc 62
2345
2346 See also \l{Qt Style Sheets Reference#padding-prop}{padding},
2347 \l{#spacing-prop}{spacing}, and \l{The Box Model}.
2348
2349 \section2 margin-top
2350 \table
2351 \row \li \b Type \li \l{#Length}{Length}
2352 \endtable
2353 The widget's top margin.
2354
2355 \section2 margin-right
2356 \table
2357 \row \li \b Type \li \l{#Length}{Length}
2358 \endtable
2359 The widget's right margin.
2360
2361 \section2 margin-bottom
2362 \table
2363 \row \li \b Type \li \l{#Length}{Length}
2364 \endtable
2365 The widget's bottom margin.
2366
2367 \section2 margin-left
2368 \table
2369 \row \li \b Type \li \l{#Length}{Length}
2370 \endtable
2371 The widget's left margin.
2372
2373 \section2 max-height
2374 \target max-height-prop
2375 \table
2376 \row \li \b Type \li \l{#Length}{Length}
2377 \endtable
2378
2379 The widget's or a subcontrol's maximum height.
2380
2381 This property is supported by QAbstractItemView
2382 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2383 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2384 QMenuBar, QPushButton, QRadioButton, QSizeGrip, QSpinBox,
2385 QSplitter, QStatusBar, QTextEdit, and QToolTip.
2386
2387 The value is relative to the contents rect in the \l{The
2388 Box Model}{box model}.
2389
2390 Example:
2391
2392 \snippet code/doc_src_stylesheet.qdoc 63
2393
2394 See also \l{#max-width-prop}{max-width}.
2395
2396 \section2 max-width
2397 \target max-width-prop
2398 \table
2399 \row \li \b Type \li \l{#Length}{Length}
2400 \endtable
2401
2402 The widget's or a subcontrol's maximum width.
2403
2404 This property is supported by QAbstractItemView
2405 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2406 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2407 QMenuBar, QPushButton, QRadioButton, QSizeGrip, QSpinBox,
2408 QSplitter, QStatusBar, QTextEdit, and QToolTip.
2409
2410 The value is relative to the contents rect in the \l{The
2411 Box Model}{box model}.
2412
2413 Example:
2414
2415 \snippet code/doc_src_stylesheet.qdoc 64
2416
2417 See also \l{#max-height-prop}{max-height}.
2418
2419 \section2 messagebox-text-interaction-flags*
2420 \target messagebox-text-interaction-flags-prop
2421 \table
2422 \row \li \b Type \li \l{#Number}{Number}
2423 \endtable
2424
2425 The interaction behavior for text in a message box.
2426 Possible values are based on Qt::TextInteractionFlags.
2427
2428 If this property is not specified, it defaults to the
2429 value specified by the current style for the
2430 \l{QStyle::}{SH_MessageBox_TextInteractionFlags} style
2431 hint.
2432
2433 Example:
2434
2435 \snippet code/doc_src_stylesheet.qdoc 65
2436
2437 \section2 min-height
2438 \target min-height-prop
2439 \table
2440 \row \li \b Type \li \l{#Length}{Length}
2441 \endtable
2442
2443 The widget's or a subcontrol's minimum height.
2444
2445 This property is supported by QAbstractItemView
2446 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2447 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2448 QMenuBar, QPushButton, QRadioButton, QSizeGrip, QSpinBox,
2449 QSplitter, QStatusBar, QTextEdit, QToolButton, and QToolTip.
2450
2451 If this property is not specified, the minimum height is
2452 derived based on the widget's contents and the style.
2453
2454 The value is relative to the contents rect in the \l{The
2455 Box Model}{box model}.
2456
2457 Example:
2458
2459 \snippet code/doc_src_stylesheet.qdoc 66
2460
2461 \note Setting this property might allow widgets to shrink
2462 smaller than the space required for the contents.
2463
2464 See also \l{#min-width-prop}{min-width}.
2465
2466 \section2 min-width
2467 \target min-width-prop
2468 \table
2469 \row \li \b Type \li \l{#Length}{Length}
2470 \endtable
2471
2472 The widget's or a subcontrol's minimum width.
2473
2474 This property is supported by QAbstractItemView
2475 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2476 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2477 QMenuBar, QPushButton, QRadioButton, QSizeGrip, QSpinBox,
2478 QSplitter, QStatusBar, QTextEdit, QToolButton, and QToolTip.
2479
2480 If this property is not specified, the minimum width is
2481 derived based on the widget's contents and the style.
2482
2483 The value is relative to the contents rect in the \l{The
2484 Box Model}{box model}.
2485
2486 Example:
2487
2488 \snippet code/doc_src_stylesheet.qdoc 67
2489
2490 \note Setting this property might allow widgets to shrink
2491 smaller than the space required for the contents.
2492
2493 See also \l{#min-height-prop}{min-height}.
2494
2495 \section2 opacity*
2496 \target opacity-prop
2497 \table
2498 \row \li \b Type \li \l{#Number}{Number}
2499 \endtable
2500
2501 The opacity for a widget. Possible values are from 0
2502 (transparent) to 255 (opaque). For the moment, this is
2503 only supported for \l{QToolTip}{tooltips}.
2504
2505 If this property is not specified, it defaults to the
2506 value specified by the current style for the
2507 \l{QStyle::}{SH_ToolTipLabel_Opacity} style hint.
2508
2509 Example:
2510
2511 \snippet code/doc_src_stylesheet.qdoc 68
2512
2513 \section2 outline
2514
2515 The outline drawn around the object's border.
2516
2517 \section2 outline-color
2518 \table
2519 \row \li \b Type \li \l{#Color}{Color}
2520 \endtable
2521
2522 The color of the outline.
2523 See also \l{Qt Style Sheets Reference#border-color-prop}{border-color}
2524
2525 \section2 outline-offset
2526 \table
2527 \row \li \b Type \li \l{#Length}{Length}
2528 \endtable
2529
2530 The outline's offset from the border of the widget.
2531
2532 \section2 outline-style
2533
2534 Specifies the pattern used to draw the outline.
2535 See also \l{Qt Style Sheets Reference#border-style-prop}{border-style}
2536
2537 \section2 outline-radius
2538
2539 Adds rounded corners to the outline.
2540
2541 \section2 outline-bottom-left-radius
2542 \table
2543 \row \li \b Type \li \l{#Radius}{Radius}
2544 \endtable
2545
2546 The radius for the bottom-left rounded corner of the outline.
2547
2548 \section2 outline-bottom-right-radius
2549 \table
2550 \row \li \b Type \li \l{#Radius}{Radius}
2551 \endtable
2552
2553 The radius for the bottom-right rounded corner of the outline.
2554
2555 \section2 outline-top-left-radius
2556 \table
2557 \row \li \b Type \li \l{#Radius}{Radius}
2558 \endtable
2559
2560 The radius for the top-left corner of the outline.
2561
2562 \section2 outline-top-right-radius
2563 \table
2564 \row \li \b Type \li \l{#Radius}{Radius}
2565 \endtable
2566
2567 The radius for the top-right rounded corner of the outline.
2568
2569 \section2 padding
2570 \target padding-prop
2571 \table
2572 \row \li \b Type \li \l{#Box Lengths}{Box Lengths}
2573 \endtable
2574
2575 The widget's padding. Equivalent to specifying \c
2576 padding-top, \c padding-right, \c padding-bottom, and \c
2577 padding-left.
2578
2579 This property is supported by QAbstractItemView
2580 subclasses, QAbstractSpinBox subclasses, QCheckBox,
2581 QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu,
2582 QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit,
2583 and QToolTip.
2584
2585 If this property is not specified, it defaults to \c 0.
2586
2587 Example:
2588
2589 \snippet code/doc_src_stylesheet.qdoc 69
2590
2591 See also \l{#margin-prop}{margin},
2592 \l{#spacing-prop}{spacing}, and \l{The Box Model}.
2593
2594 \section2 padding-top
2595 \table
2596 \row \li \b Type \li \l{#Length}{Length}
2597 \endtable
2598
2599 The widget's top padding.
2600
2601 \section2 padding-right
2602 \table
2603 \row \li \b Type \li \l{#Length}{Length}
2604 \endtable
2605
2606 The widget's right padding.
2607
2608 \section2 padding-bottom
2609 \table
2610 \row \li \b Type \li \l{#Length}{Length}
2611 \endtable
2612
2613 The widget's bottom padding.
2614
2615 \section2 padding-left
2616 \table
2617 \row \li \b Type \li \l{#Length}{Length}
2618 \endtable
2619
2620 The widget's left padding.
2621
2622 \section2 paint-alternating-row-colors-for-empty-area
2623 \target paint-alternating-row-colors-for-empty-area-prop
2624 \table
2625 \row \li \b Type \li \c bool
2626 \endtable
2627
2628 Whether the QTreeView paints alternating row colors for the empty
2629 area (i.e the area where there are no items)
2630
2631 \section2 placeholder-text-color*
2632 \target placeholder-text-color-prop
2633 \table
2634 \row \li \b Type \li \l{#Brush}{Brush} \br
2635 \endtable
2636
2637 The color used for the placeholder text of text editing widgets.
2638
2639 If this property is not set, the default value is whatever
2640 is set for the palette's \l{QPalette::}{PlaceholderText}
2641 role.
2642
2643 Example:
2644
2645 \snippet code/doc_src_stylesheet.qdoc 163
2646
2647 Available since 6.5.
2648
2649 \section2 position
2650 \target position-prop
2651 \table
2652 \row \li \b Type \li \c relative \br
2653 | \c absolute
2654 \endtable
2655
2656 Whether offsets specified using \l{Qt Style Sheets Reference#left-prop}{left},
2657 \l{#right-prop}{right}, \l{Qt Style Sheets Reference#top-prop}{top}, and
2658 \l{#bottom-prop}{bottom} are relative or absolute
2659 coordinates.
2660
2661 If this property is not specified, it defaults to \c
2662 relative.
2663
2664 \section2 right
2665 \target right-prop
2666 \table
2667 \row \li \b Type \li \l{#Length}{Length}
2668 \endtable
2669
2670 If \l{#position-prop}{position} is \c relative (the
2671 default), moves a subcontrol by a certain offset to
2672 the left; specifying \tt{right: \e{x}} is then equivalent
2673 to specifying \tt{\l{Qt Style Sheets Reference#left-prop}{left}: -\e{x}}.
2674
2675 If \l{#position-prop}{position} is \c absolute, the \c
2676 right property specifies the subcontrol's right edge in
2677 relation to the parent's right edge (see also
2678 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}).
2679
2680 Example:
2681
2682 \snippet code/doc_src_stylesheet.qdoc 70
2683
2684 See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{Qt Style Sheets Reference#top-prop}{top}, and
2685 \l{#bottom-prop}{bottom}.
2686
2687 \section2 selection-background-color*
2688 \target selection-background-color-prop
2689 \table
2690 \row \li \b Type \li \l{#Brush}{Brush}
2691 \endtable
2692
2693 The background of selected text or items.
2694
2695 This property is supported by all widgets that respect
2696 the \l QWidget::palette and that show selection text.
2697
2698 If this property is not set, the default value is
2699 whatever is set for the palette's
2700 \l{QPalette::}{Highlight} role.
2701
2702 Example:
2703
2704 \snippet code/doc_src_stylesheet.qdoc 71
2705
2706 See also \l{#selection-color-prop}{selection-color} and
2707 \l{Qt Style Sheets Reference#background-prop}{background}.
2708
2709
2710 \section2 selection-color*
2711 \target selection-color-prop
2712 \table
2713 \row \li \b Type \li \l{#Brush}{Brush} \br
2714 \endtable
2715
2716 The foreground of selected text or items.
2717
2718 This property is supported by all widgets that respect
2719 the \l QWidget::palette and that show selection text.
2720
2721 If this property is not set, the default value is
2722 whatever is set for the palette's
2723 \l{QPalette::}{HighlightedText} role.
2724
2725 Example:
2726
2727 \snippet code/doc_src_stylesheet.qdoc 72
2728
2729 See also
2730 \l{#selection-background-color-prop}{selection-background-color}
2731 and \l{#color-prop}{color}.
2732
2733
2734 \section2 show-decoration-selected*
2735 \target show-decoration-selected-prop
2736 \table
2737 \row \li \b Type \li \l{#Boolean}{Boolean}
2738 \endtable
2739
2740 Controls whether selections in a QListView cover the
2741 entire row or just the extent of the text.
2742
2743 If this property is not specified, it defaults to the
2744 value specified by the current style for the
2745 \l{QStyle::}{SH_ItemView_ShowDecorationSelected} style
2746 hint.
2747
2748 Example:
2749
2750 \snippet code/doc_src_stylesheet.qdoc 73
2751
2752 \section2 spacing*
2753 \target spacing-prop
2754 \table
2755 \row \li \b Type \li \l{#Length}{Length}
2756 \endtable
2757
2758 Internal spacing in the widget.
2759
2760 This property is supported by QCheckBox, checkable
2761 \l{QGroupBox}es, QMenuBar, and QRadioButton.
2762
2763 If this property is not specified, the default value
2764 depends on the widget and on the current style.
2765
2766 Example:
2767
2768 \snippet code/doc_src_stylesheet.qdoc 74
2769
2770 See also \l{Qt Style Sheets Reference#padding-prop}{padding} and
2771 \l{#margin-prop}{margin}.
2772
2773
2774 \section2 subcontrol-origin*
2775 \target subcontrol-origin-prop
2776 \table
2777 \row \li \b Type \li \l{#Origin}{Origin}
2778 \endtable
2779
2780 The origin rectangle of the subcontrol within the
2781 parent element.
2782
2783 If this property is not specified, the default is \c
2784 padding.
2785
2786 Example:
2787
2788 \snippet code/doc_src_stylesheet.qdoc 75
2789
2790 See also
2791 \l{Qt Style Sheets Reference#subcontrol-position-prop}{subcontrol-position}.
2792
2793 \section2 subcontrol-position*
2794 \target subcontrol-position-prop
2795 \table
2796 \row \li \b Type \li \l{#Alignment}{Alignment}
2797 \endtable
2798
2799 The alignment of the subcontrol within the origin
2800 rectangle specified by \l{Qt Style Sheets Reference#subcontrol-origin-prop}
2801 {subcontrol-origin}.
2802
2803 If this property is not specified, it defaults to a value
2804 that depends on the subcontrol.
2805
2806 Example:
2807
2808 \snippet code/doc_src_stylesheet.qdoc 76
2809
2810 See also
2811 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}.
2812
2813 \section2 titlebar-show-tooltips-on-buttons
2814 \target titlebar-show-tooltips-on-buttons-prop
2815 \table
2816 \row \li \b Type \li \c bool
2817 \endtable
2818
2819 Whether tool tips are shown on window title bar buttons.
2820
2821
2822 \section2 widget-animation-duration*
2823 \target widget-animation-duration
2824 \table
2825 \row \li \b Type \li \l{#Number}{Number}
2826 \endtable
2827
2828 How much an animation should last (in milliseconds).
2829 A value equal to zero means that the animations will be disabled.
2830
2831 If this property is not specified, it defaults to the
2832 value specified by the current style for the
2833 \l{QStyle::}{SH_Widget_Animation_Duration} style hint.
2834
2835 Available since Qt 5.10.
2836
2837 Example:
2838
2839 \snippet code/doc_src_stylesheet.qdoc 162
2840
2841 \section2 text-align
2842 \target text-align-prop
2843 \table
2844 \row \li \b Type \li \l{#Alignment}{Alignment}
2845 \endtable
2846
2847 The alignment of text and icon within the contents of the widget.
2848
2849 If this value is not specified, it defaults to the value
2850 that depends on the native style.
2851
2852 Example:
2853
2854 \snippet code/doc_src_stylesheet.qdoc 77
2855
2856 This property is currently supported only by QPushButton
2857 and QProgressBar.
2858
2859 \section2 text-decoration
2860 \table
2861 \row \li \b Type
2862 \li \c none \br
2863 \c underline \br
2864 \c overline \br
2865 \c line-through
2866 \endtable
2867
2868 Additional text effects.
2869
2870
2871 \section2 top
2872 \target top-prop
2873 \table
2874 \row \li \b Type \li \l{#Length}{Length}
2875 \endtable
2876
2877 If \l{#position-prop}{position} is \c relative (the
2878 default), moves a subcontrol by a certain offset
2879 down.
2880
2881 If \l{#position-prop}{position} is \c absolute, the \c top
2882 property specifies the subcontrol's top edge in relation
2883 to the parent's top edge (see also
2884 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}).
2885
2886 If this property is not specified, it defaults to \c 0.
2887
2888 Example:
2889
2890 \snippet code/doc_src_stylesheet.qdoc 78
2891
2892 See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{#right-prop}{right}, and
2893 \l{#bottom-prop}{bottom}.
2894
2895 \section2 width
2896 \target width-prop
2897 \table
2898 \row \li \b Type \li \l{#Length}{Length}
2899 \endtable
2900
2901 The width of a subcontrol (or a widget in some cases).
2902
2903 If this property is not specified, it defaults to a value
2904 that depends on the subcontrol/widget and on the current style.
2905
2906 \warning Unless otherwise specified, this property has no effect
2907 when set on widgets. If you want a widget with a fixed width, set
2908 the \l{#min-width-prop}{min-width} and
2909 \l{#max-width-prop}{max-width} to the same value.
2910
2911 Example:
2912
2913 \snippet code/doc_src_stylesheet.qdoc 79
2914
2915 See also \l{#height-prop}{height}.
2916
2917 \section2 word-spacing
2918 \table
2919 \row \li \b Type \li \l{#Length}{Length}
2920 \endtable
2921
2922 Space between each word in a string within a widget.
2923
2924 \section2 -qt-background-role
2925 \table
2926 \row \li \b Type \li \l{#paletterole}{PaletteRole}
2927 \endtable
2928
2929 The \c{background-color} for the subcontrol or widget based on the
2930 chosen role.
2931
2932 \section2 -qt-style-features
2933 \table
2934 \row \li \b Type \li \c list
2935 \endtable
2936
2937 The list of CSS properties that you want to apply Qt-specific styles on.
2938
2939 \note The \c list can only include properties that are not pixmap-based.
2940
2941 \target list of icons
2942 \section1 List of Icons
2943
2944 Icons used in Qt can be customized using the following properties. Each of
2945 the properties listed in this section have the type \l{#Icon}{Icon}.
2946
2947 Note that for icons to appear in buttons in a QDialogButtonBox, you need to
2948 set the dialogbuttonbox-buttons-have-icons property to true. Also, to
2949 customize the size of the icons, use the icon-size property.
2950
2951 \table 100%
2952 \header
2953 \li Name
2954 \li QStyle::StandardPixmap
2955
2956 \row
2957 \li backward-icon
2958 \li QStyle::SP_ArrowBack
2959
2960 \row
2961 \li cd-icon
2962 \li QStyle::SP_DriveCDIcon
2963
2964 \row
2965 \li computer-icon
2966 \li QStyle::SP_ComputerIcon
2967
2968 \row
2969 \li desktop-icon
2970 \li QStyle::SP_DesktopIcon
2971
2972 \row
2973 \li dialog-apply-icon
2974 \li QStyle::SP_DialogApplyButton
2975
2976 \row
2977 \li dialog-cancel-icon
2978 \li QStyle::SP_DialogCancelButton
2979
2980 \row
2981 \li dialog-close-icon
2982 \li QStyle::SP_DialogCloseButton
2983
2984 \row
2985 \li dialog-discard-icon
2986 \li QStyle::SP_DialogDiscardButton
2987
2988 \row
2989 \li dialog-help-icon
2990 \li QStyle::SP_DialogHelpButton
2991
2992 \row
2993 \li dialog-no-icon
2994 \li QStyle::SP_DialogNoButton
2995
2996 \row
2997 \li dialog-ok-icon
2998 \li QStyle::SP_DialogOkButton
2999
3000 \row
3001 \li dialog-open-icon
3002 \li QStyle::SP_DialogOpenButton
3003
3004 \row
3005 \li dialog-reset-icon
3006 \li QStyle::SP_DialogResetButton
3007
3008 \row
3009 \li dialog-save-icon
3010 \li QStyle::SP_DialogSaveButton
3011
3012 \row
3013 \li dialog-yes-icon
3014 \li QStyle::SP_DialogYesButton
3015
3016 \row
3017 \li directory-closed-icon
3018 \li QStyle::SP_DirClosedIcon
3019
3020 \row
3021 \li directory-icon
3022 \li QStyle::SP_DirIcon
3023
3024 \row
3025 \li directory-link-icon
3026 \li QStyle::SP_DirLinkIcon
3027
3028 \row
3029 \li directory-open-icon
3030 \li QStyle::SP_DirOpenIcon
3031
3032 \row
3033 \li dockwidget-close-icon
3034 \li QStyle::SP_DockWidgetCloseButton
3035
3036 \row
3037 \li downarrow-icon
3038 \li QStyle::SP_ArrowDown
3039
3040 \row
3041 \li dvd-icon
3042 \li QStyle::SP_DriveDVDIcon
3043
3044 \row
3045 \li file-icon
3046 \li QStyle::SP_FileIcon
3047
3048 \row
3049 \li file-link-icon
3050 \li QStyle::SP_FileLinkIcon
3051
3052 \omit
3053 \row
3054 \li filedialog-backward-icon
3055 \li QStyle::SP_FileDialogBack
3056 \endomit
3057
3058 \row
3059 \li filedialog-contentsview-icon
3060 \li QStyle::SP_FileDialogContentsView
3061
3062 \row
3063 \li filedialog-detailedview-icon
3064 \li QStyle::SP_FileDialogDetailedView
3065
3066 \row
3067 \li filedialog-end-icon
3068 \li QStyle::SP_FileDialogEnd
3069
3070 \row
3071 \li filedialog-infoview-icon
3072 \li QStyle::SP_FileDialogInfoView
3073
3074 \row
3075 \li filedialog-listview-icon
3076 \li QStyle::SP_FileDialogListView
3077
3078 \row
3079 \li filedialog-new-directory-icon
3080 \li QStyle::SP_FileDialogNewFolder
3081
3082 \row
3083 \li filedialog-parent-directory-icon
3084 \li QStyle::SP_FileDialogToParent
3085
3086 \row
3087 \li filedialog-start-icon
3088 \li QStyle::SP_FileDialogStart
3089
3090 \row
3091 \li floppy-icon
3092 \li QStyle::SP_DriveFDIcon
3093
3094 \row
3095 \li forward-icon
3096 \li QStyle::SP_ArrowForward
3097
3098 \row
3099 \li harddisk-icon
3100 \li QStyle::SP_DriveHDIcon
3101
3102 \row
3103 \li home-icon
3104 \li QStyle::SP_DirHomeIcon
3105
3106 \row
3107 \li lineedit-clear-button-icon
3108 \li QStyle::SP_LineEditClearButton
3109
3110 \row
3111 \li leftarrow-icon
3112 \li QStyle::SP_ArrowLeft
3113
3114 \row
3115 \li messagebox-critical-icon
3116 \li QStyle::SP_MessageBoxCritical
3117
3118 \row
3119 \li messagebox-information-icon
3120 \li QStyle::SP_MessageBoxInformation
3121
3122 \row
3123 \li messagebox-question-icon
3124 \li QStyle::SP_MessageBoxQuestion
3125
3126 \row
3127 \li messagebox-warning-icon
3128 \li QStyle::SP_MessageBoxWarning
3129
3130 \row
3131 \li network-icon
3132 \li QStyle::SP_DriveNetIcon
3133
3134 \row
3135 \li rightarrow-icon
3136 \li QStyle::SP_ArrowRight
3137
3138 \row
3139 \li titlebar-contexthelp-icon
3140 \li QStyle::SP_TitleBarContextHelpButton
3141
3142 \row
3143 \li titlebar-maximize-icon
3144 \li QStyle::SP_TitleBarMaxButton
3145
3146 \row
3147 \li titlebar-menu-icon
3148 \li QStyle::SP_TitleBarMenuButton
3149
3150 \row
3151 \li titlebar-minimize-icon
3152 \li QStyle::SP_TitleBarMinButton
3153
3154 \row
3155 \li titlebar-normal-icon
3156 \li QStyle::SP_TitleBarNormalButton
3157
3158 \row
3159 \li titlebar-shade-icon
3160 \li QStyle::SP_TitleBarShadeButton
3161
3162 \row
3163 \li titlebar-unshade-icon
3164 \li QStyle::SP_TitleBarUnshadeButton
3165
3166 \row
3167 \li trash-icon
3168 \li QStyle::SP_TrashIcon
3169
3170 \row
3171 \li uparrow-icon
3172 \li QStyle::SP_ArrowUp
3173
3174 \endtable
3175
3176 \section1 List of Property Types
3177
3178 The following table summarizes the syntax and meaning of the
3179 different property types.
3180
3181 \table 100%
3182 \header
3183 \li Type
3184 \li Syntax
3185 \li Description
3186
3187 \row
3188 \li \b Alignment \target Alignment
3189 \li \{ \c top \br
3190 | \c bottom \br
3191 | \c left \br
3192 | \c right \br
3193 | \c center \}*
3194 \li Horizontal and/or vertical alignment.
3195
3196 Example:
3197
3198 \snippet code/doc_src_stylesheet.qdoc 80
3199
3200 \row
3201 \li \b Attachment \target Attachment
3202 \li \{ \c scroll \br
3203 | \c fixed \}*
3204 \li Scroll or fixed attachment.
3205
3206 \row
3207 \li \b Background \target Background
3208 \li \{ \l{#Brush}{Brush} \br
3209 | \l{#Url}{Url} \br
3210 | \l{#Repeat}{Repeat} \br
3211 | \l{#Alignment}{Alignment} \}*
3212 \li A sequence of \l{#Brush}{Brush}, \l{#Url}{Url},
3213 \l{#Repeat}{Repeat}, and \l{#Alignment}{Alignment}.
3214
3215 \row
3216 \li \b Boolean \target Boolean
3217 \li 0 | 1
3218 \li True (\c 1) or false (\c 0).
3219
3220 Example:
3221
3222 \snippet code/doc_src_stylesheet.qdoc 81
3223
3224 \row
3225 \li \b Border \target Border
3226 \li \{ \l{#Border Style}{Border Style} \br
3227 | \l{#Length}{Length} \br
3228 | \l{#Brush}{Brush} \}*
3229 \li Shorthand border property.
3230
3231 \row
3232 \li \b{Border Image} \target Border Image
3233 \li \c none \br
3234 | \l{Url} \l{Number}\{4\} \br (\c stretch | \c repeat){0,2}
3235 \li A border image is an image that is composed of nine parts
3236 (top left, top center, top right, center left, center,
3237 center right, bottom left, bottom center, and bottom
3238 right). When a border of a certain size is required, the
3239 corner parts are used as is, and the top, right, bottom,
3240 and left parts are stretched or repeated to produce a
3241 border with the desired size.
3242
3243 See the
3244 \l{http://www.w3.org/TR/css3-background/#the-border-image}
3245 {CSS3 Draft Specification} for details.
3246
3247 \row
3248 \li \b{Border Style} \target Border Style
3249 \li \c dashed \br
3250 | \c dot-dash \br
3251 | \c dot-dot-dash \br
3252 | \c dotted \br
3253 | \c double \br
3254 | \c groove \br
3255 | \c inset \br
3256 | \c outset \br
3257 | \c ridge \br
3258 | \c solid \br
3259 | \c none
3260 \li Specifies the pattern used to draw a border.
3261 See the \l{http://www.w3.org/TR/css3-background/#border-style}
3262 {CSS3 Draft Specification} for details.
3263
3264 \row
3265 \li \b{Box Colors} \target Box Colors
3266 \li \l{#Brush}{Brush}\{1,4\}
3267 \li One to four occurrences of \l{#Brush}{Brush}, specifying the top,
3268 right, bottom, and left edges of a box, respectively. If
3269 the left color is not specified, it is taken to be the
3270 same as the right color. If the bottom color is not
3271 specified, it is taken to be the same as the top color. If
3272 the right color is not specified, it is taken to be the
3273 same as the top color.
3274
3275 Example:
3276
3277 \snippet code/doc_src_stylesheet.qdoc 82
3278
3279 \row
3280 \li \b{Box Lengths} \target Box Lengths
3281 \li \l{#Length}{Length}\{1,4\}
3282 \li One to four occurrences of \l{#Length}{Length}, specifying the
3283 top, right, bottom, and left edges of a box,
3284 respectively. If the left length is not specified, it is
3285 taken to be the same as the right length. If the bottom
3286 length is not specified, is it taken to be the same as the
3287 top length. If the right length is not specified, it is
3288 taken to be the same as the top length.
3289
3290 Examples:
3291
3292 \snippet code/doc_src_stylesheet.qdoc 83
3293
3294 \row
3295 \li \b{Brush} \target Brush
3296 \li \l{#Color}{Color} \br
3297 | \l{Gradient} \br
3298 | \l{PaletteRole}
3299 \li Specifies a Color or a Gradient or an entry in the Palette.
3300
3301 \row
3302 \li \b{Color} \target Color
3303 \li \tt{rgb(\e{r}, \e{g}, \e{b})} \br
3304 | \tt{rgba(\e{r}, \e{g}, \e{b}, \e{a})} \br
3305 | \tt{hsv(\e{h}, \e{s}, \e{v})} \br
3306 | \tt{hsva(\e{h}, \e{s}, \e{v}, \e{a})} \br
3307 | \tt{hsl(\e{h}, \e{s}, \e{l})} \br
3308 | \tt{hsla(\e{h}, \e{s}, \e{l}, \e{a})} \br
3309 | \tt{#\e{rrggbb}} \br
3310 | \l{QColor::fromString()}{Color Name} \br
3311 \li Specifies a color as RGB (red, green, blue), RGBA (red,
3312 green, blue, alpha), HSV (hue, saturation, value), HSVA
3313 (hue, saturation, value, alpha), HSL (hue, saturation,
3314 lightness), HSLA (hue, saturation, lightness, alpha) or a
3315 named color. The \c rgb() or \c rgba() syntax can be used
3316 with integer values between 0 and 255, or with percentages.
3317 The value of s, v, l and a in \c hsv(), \c hsva() \c hsl()
3318 or \c hsla() must all be in the range 0-255 or with
3319 percentages, the value of h must be in the range 0-359.
3320 The support for HSL(A) is available since 5.13.
3321
3322 Examples:
3323
3324 \snippet code/doc_src_stylesheet.qdoc 84
3325
3326 \note The RGB colors allowed are the same as those allowed with
3327 CSS 2.1, as listed
3328 \l{http://www.w3.org/TR/CSS21/syndata.html#color-units}{here}.
3329
3330 \row
3331 \li \b{Font} \target Font
3332 \li (\l{#Font Style}{Font Style} | \l{#Font Weight}{Font Weight}){0,2} \l{#Font Size}{Font Size} String
3333 \li Shorthand font property.
3334
3335 \row
3336 \li \b{Font Size} \target Font Size
3337 \li \l{Length}
3338 \li The size of a font.
3339
3340 \row
3341 \li \b{Font Style} \target Font Style
3342 \li \c normal \br
3343 | \c italic \br
3344 | \c oblique
3345 \li The style of a font.
3346
3347 \row
3348 \li \b{Font Weight} \target Font Weight
3349 \li \c normal \br
3350 | \c bold \br
3351 | \c 100 \br
3352 | \c 200 \br
3353 ... \br
3354 | \c 900
3355 \li The weight of a font.
3356
3357 \row
3358 \li \b{Gradient} \target Gradient
3359 \li \c qlineargradient \br
3360 | \c qradialgradient \br
3361 | \c qconicalgradient
3362 \li Specifies gradient fills. There are three types of gradient fills:
3363
3364 \list
3365 \li \e{Linear} gradients interpolate colors between start and
3366 end points.
3367 \li \e{Radial} gradients interpolate colors between a focal
3368 point and end points on a circle surrounding it.
3369 \li \e{Conical} gradients interpolate colors around a center
3370 point.
3371 \endlist
3372
3373 Gradients are specified in Object Bounding Mode. Imagine the box
3374 in which the gradient is rendered, to have its top left corner at (0, 0)
3375 and its bottom right corner at (1, 1). Gradient parameters are
3376 then specified as percentages from 0 to 1. These values are
3377 extrapolated to actual box coordinates at runtime. It is possible
3378 specify values that lie outside the bounding box (-0.6 or 1.8, for
3379 instance).
3380
3381 \warning The stops have to appear sorted in ascending order.
3382
3383 Examples:
3384
3385 \snippet code/doc_src_stylesheet.qdoc 85
3386
3387 \row
3388 \li \b{Icon} \target Icon
3389 \li (\l{#Url}{Url} (\c disabled | \c active | \c normal | \c selected)?
3390 (\c on | \c off)? )*
3391 \li A list of url, QIcon::Mode and QIcon::State.
3392
3393 Example:
3394 \snippet code/doc_src_stylesheet.qdoc 86
3395
3396 \row
3397 \li \b{Length} \target Length
3398 \li \l{#Number}{Number} (\c px | \c pt | \c em | \c ex)?
3399 \li A number followed by a measurement unit. The CSS standard recommends
3400 that user agents must
3401 \l{http://www.w3.org/TR/CSS21/syndata.html#illegalvalues}{ignore}
3402 a declaration with an illegal value. In Qt, it is mandatory to
3403 specify measurement units. For compatibility with earlier versions
3404 of Qt, numbers without measurement units are treated as pixels
3405 in most contexts. The supported units are:
3406
3407 \list
3408 \li \c px: pixels
3409 \li \c pt: the size of one point (i.e., 1/72 of an inch)
3410 \li \c em: the size relative to the font size of the element
3411 (e.g., 2em means 2 times the size of the font)
3412 \li \c ex: the x-height of the font (i.e., the height of 'x')
3413 \endlist
3414
3415 However, Qt is limited to font sizes in \c pt and \c px and any other
3416 size must be in \c px, \c em or \c ex.
3417
3418 \row
3419 \li \b{Number} \target Number
3420 \li A decimal integer or a real number
3421 \li Examples: \c 0, \c 18, \c +127, \c -255, \c 12.34, \c -.5,
3422 \c 0009.
3423
3424 \row
3425 \li \b{Origin} \target Origin
3426 \li \c margin \br
3427 | \c border \br
3428 | \c padding \br
3429 | \c content
3430 \li Indicates which of four rectangles to use.
3431
3432 \list
3433 \li \c margin: The margin rectangle. The margin falls outside the border.
3434 \li \c border: The border rectangle. This is where any border is drawn.
3435 \li \c padding: The padding rectangle. Unlike the margins,
3436 padding is located inside the border.
3437 \li \c content: The content rectangle. This specifies where
3438 the actual contents go, excluding any
3439 padding, border, or margin.
3440 \endlist
3441
3442 See also \l{The Box Model}.
3443
3444 \row
3445 \li \b{PaletteRole} \target PaletteRole
3446 \li \c alternate-base \br
3447 | \c accent \br
3448 | \c base \br
3449 | \c bright-text \br
3450 | \c button \br
3451 | \c button-text \br
3452 | \c dark \br
3453 | \c highlight \br
3454 | \c highlighted-text \br
3455 | \c light \br
3456 | \c link \br
3457 | \c link-visited \br
3458 | \c mid \br
3459 | \c midlight \br
3460 | \c placeholder-text \br
3461 | \c shadow \br
3462 | \c text \br
3463 | \c tooltip-base \br
3464 | \c tooltip-text \br
3465 | \c window \br
3466 | \c window-text \br
3467 \li These values correspond the \l{QPalette::ColorRole}{Color roles}
3468 in the widget's QPalette.
3469
3470 For example,
3471 \snippet code/doc_src_stylesheet.qdoc 87
3472
3473 \row
3474 \li \b{Radius} \target Radius
3475 \li \l{#Length}{Length}\{1, 2\}
3476 \li One or two occurrences of \l{#Length}{Length}. If only one length is
3477 specified, it is used as the radius of the quarter circle
3478 defining the corner. If two lengths are specified, the
3479 first length is the horizontal radius of a quarter
3480 ellipse, whereas the second length is the vertical radius.
3481
3482 \row
3483 \li \b{Repeat} \target Repeat
3484 \li \c repeat-x \br
3485 | \c repeat-y \br
3486 | \c repeat \br
3487 | \c no-repeat
3488 \li A value indicating the nature of repetition.
3489
3490 \list
3491 \li \c repeat-x: Repeat horizontally.
3492 \li \c repeat-y: Repeat vertically.
3493 \li \c repeat: Repeat horizontally and vertically.
3494 \li \c no-repeat: Don't repeat.
3495 \endlist
3496
3497 \row
3498 \li \b{Url} \target Url
3499 \li \tt{url(\e{filename})}
3500 \li \tt{\e{filename}} is the name of a file on the local disk
3501 or stored using \l{The Qt Resource System}. Setting an
3502 image implicitly sets the width and height of the element.
3503
3504 \endtable
3505
3506 \section1 List of Pseudo-States
3507
3508 The following pseudo-states are supported:
3509
3510 \table 100%
3511 \header
3512 \li Pseudo-State
3513 \li Description
3514
3515 \row \li \c :active \target active
3516 \li This state is set when the widget resides in an active window.
3517
3518 \row
3519 \li \c :adjoins-item \target adjoins-item-ps
3520 \li This state is set when the \l{#branch-sub}{::branch} of a QTreeView
3521 is adjacent to an item.
3522
3523 \row
3524 \li \c :alternate \target alternate-ps
3525 \li This state is set for every alternate row whe painting the row of
3526 a QAbstractItemView when QAbstractItemView::alternatingRowColors()
3527 is set to true.
3528
3529 \row
3530 \li \c :bottom \target bottom-ps
3531 \li The item is positioned at the bottom. For example, a QTabBar
3532 that has its tabs positioned at the bottom.
3533
3534 \row
3535 \li \c :checked \target checked-ps
3536 \li The item is checked. For example, the
3537 \l{QAbstractButton::checked}{checked} state of QAbstractButton.
3538
3539 \row
3540 \li \c :closable \target closable-ps
3541 \li The items can be closed. For example, the QDockWidget has the
3542 QDockWidget::DockWidgetClosable feature turned on.
3543
3544 \row
3545 \li \c :closed \target closed-ps
3546 \li The item is in the closed state. For example, an non-expanded
3547 item in a QTreeView
3548
3549 \row
3550 \li \c :default \target default-ps
3551 \li The item is the default. For example, a
3552 \l{QPushButton::default}{default} QPushButton or a default action
3553 in a QMenu.
3554
3555 \row
3556 \li \c :disabled \target disabled-ps
3557 \li The item is \l{QWidget::enabled}{disabled}.
3558
3559 \row
3560 \li \c :editable \target editable-ps
3561 \li The QComboBox is editable.
3562
3563 \row
3564 \li \c :enabled \target enabled-ps
3565 \li The item is \l{QWidget::enabled}{enabled}.
3566
3567 \row
3568 \li \c :exclusive \target exclusive-ps
3569 \li The item is part of an exclusive item group. For example, a menu
3570 item in a exclusive QActionGroup.
3571
3572 \row
3573 \li \c :first \target first-ps
3574 \li The item is the first (in a list). For example, the first
3575 tab in a QTabBar.
3576
3577 \row
3578 \li \c :flat \target flat-ps
3579 \li The item is flat. For example, a
3580 \l{QPushButton::flat}{flat} QPushButton.
3581
3582 \row
3583 \li \c :floatable \target floatable-ps
3584 \li The items can be floated. For example, the QDockWidget has the
3585 QDockWidget::DockWidgetFloatable feature turned on.
3586
3587 \row
3588 \li \c :focus \target focus-ps
3589 \li The item has \l{QWidget::hasFocus()}{input focus}.
3590
3591 \row
3592 \li \c :has-children \target has-children-ps
3593 \li The item has children. For example, an item in a
3594 QTreeView that has child items.
3595
3596 \row
3597 \li \c :has-siblings \target has-siblings-ps
3598 \li The item has siblings. For example, an item in a
3599 QTreeView that siblings.
3600
3601 \row
3602 \li \c :horizontal \target horizontal-ps
3603 \li The item has horizontal orientation
3604
3605 \row
3606 \li \c :hover \target hover-ps
3607 \li The mouse is hovering over the item.
3608
3609 \row
3610 \li \c :indeterminate \target indeterminate-ps
3611 \li The item has indeterminate state. For example, a QCheckBox
3612 or QRadioButton is \l{Qt::PartiallyChecked}{partially checked}.
3613
3614 \row
3615 \li \c :last \target last-ps
3616 \li The item is the last (in a list). For example, the last
3617 tab in a QTabBar.
3618
3619 \row
3620 \li \c :left \target left-ps
3621 \li The item is positioned at the left. For example, a QTabBar
3622 that has its tabs positioned at the left.
3623
3624 \row
3625 \li \c :maximized \target maximized-ps
3626 \li The item is maximized. For example, a maximized QMdiSubWindow.
3627
3628 \row
3629 \li \c :middle \target middle-ps
3630 \li The item is in the middle (in a list). For example, a tab
3631 that is not in the beginning or the end in a QTabBar.
3632
3633 \row
3634 \li \c :minimized \target minimized-ps
3635 \li The item is minimized. For example, a minimized QMdiSubWindow.
3636
3637 \row
3638 \li \c :movable \target movable-ps
3639 \li The item can be moved around. For example, the QDockWidget has the
3640 QDockWidget::DockWidgetMovable feature turned on.
3641
3642 \row
3643 \li \c :no-frame \target no-frame-ps
3644 \li The item has no frame. For example, a frameless QSpinBox
3645 or QLineEdit.
3646
3647 \row
3648 \li \c :non-exclusive \target non-exclusive-ps
3649 \li The item is part of a non-exclusive item group. For example, a menu
3650 item in a non-exclusive QActionGroup.
3651
3652 \row
3653 \li \c :off \target off-ps
3654 \li For items that can be toggled, this applies to items
3655 in the "off" state.
3656
3657 \row
3658 \li \c :on \target on-ps
3659 \li For items that can be toggled, this applies to widgets
3660 in the "on" state.
3661
3662 \row
3663 \li \c :only-one \target only-one-ps
3664 \li The item is the only one (in a list). For example, a lone tab
3665 in a QTabBar.
3666
3667 \row
3668 \li \c :open \target open-ps
3669 \li The item is in the open state. For example, an expanded
3670 item in a QTreeView, or a QComboBox or QPushButton with
3671 an open menu.
3672
3673 \row
3674 \li \c :next-selected \target next-selected-ps
3675 \li The next item (in a list) is selected. For example, the
3676 selected tab of a QTabBar is next to this item.
3677
3678 \row
3679 \li \c :pressed \target pressed-ps
3680 \li The item is being pressed using the mouse.
3681
3682 \row
3683 \li \c :previous-selected \target previous-selected-ps
3684 \li The previous item (in a list) is selected. For example, a
3685 tab in a QTabBar that is next to the selected tab.
3686
3687 \row
3688 \li \c :read-only \target read-only-ps
3689 \li The item is marked read only or non-editable. For example,
3690 a read only QLineEdit or a non-editable QComboBox.
3691
3692 \row
3693 \li \c :right \target right-ps
3694 \li The item is positioned at the right. For example, a QTabBar
3695 that has its tabs positioned at the right.
3696
3697 \row
3698 \li \c :selected \target selected-ps
3699 \li The item is selected. For example, the selected tab in
3700 a QTabBar or the selected item in a QMenu.
3701
3702 \row
3703 \li \c :top \target top-ps
3704 \li The item is positioned at the top. For example, a QTabBar
3705 that has its tabs positioned at the top.
3706
3707 \row
3708 \li \c :unchecked \target unchecked-ps
3709 \li The item is
3710 \l{QAbstractButton::checked}{unchecked}.
3711
3712 \row
3713 \li \c :vertical \target vertical-ps
3714 \li The item has vertical orientation.
3715
3716 \row
3717 \li \c :window \target window-ps
3718 \li The widget is a window (i.e top level widget)
3719
3720 \endtable
3721
3722 \target subcontrols
3723 \section1 List of Sub-Controls
3724
3725 The following subcontrols are available:
3726
3727 \table 100%
3728 \header
3729 \li Sub-Control
3730 \li Description
3731
3732 \row
3733 \li \c ::add-line \target add-line-sub
3734 \li The button to add a line of a QScrollBar.
3735
3736 \row
3737 \li \c ::add-page \target add-page-sub
3738 \li The region between the handle (slider) and the \l{#add-line-sub}{add-line}
3739 of a QScrollBar.
3740
3741 \row
3742 \li \c ::branch \target branch-sub
3743 \li The branch indicator of a QTreeView.
3744
3745 \row
3746 \li \c ::chunk \target chunk-sub
3747 \li The progress chunk of a QProgressBar.
3748
3749 \row
3750 \li \c ::close-button \target close-button-sub
3751 \li The close button of a QDockWidget or tabs of QTabBar
3752
3753 \row
3754 \li \c ::corner \target corner-sub
3755 \li The corner between two scrollbars in a QAbstractScrollArea
3756
3757 \row
3758 \li \c ::down-arrow \target down-arrow-sub
3759 \li The down arrow of a QComboBox, QHeaderView (sort indicator),
3760 QScrollBar or QSpinBox.
3761
3762 \row
3763 \li \c ::down-button \target down-button-sub
3764 \li The down button of a QScrollBar or a QSpinBox.
3765
3766 \row
3767 \li \c ::drop-down \target drop-down-sub
3768 \li The drop-down button of a QComboBox.
3769
3770 \row
3771 \li \c ::float-button \target float-button-sub
3772 \li The float button of a QDockWidget
3773
3774 \row
3775 \li \c ::groove \target groove-sub
3776 \li The groove of a QSlider.
3777
3778 \row
3779 \li \c ::indicator \target indicator-sub
3780 \li The indicator of a QAbstractItemView, a QCheckBox, a QRadioButton,
3781 a checkable QMenu item or a checkable QGroupBox.
3782
3783 \row
3784 \li \c ::handle \target handle-sub
3785 \li The handle (slider) of a QScrollBar, a QSplitter, or a QSlider.
3786
3787 \row
3788 \li \c ::icon \target icon-sub
3789 \li The icon of a QAbstractItemView or a QMenu.
3790
3791 \row
3792 \li \c ::item \target item-sub
3793 \li An item of a QAbstractItemView, a QMenuBar, a QMenu, or
3794 a QStatusBar.
3795
3796 \row
3797 \li \c ::left-arrow \target left-arrow-sub
3798 \li The left arrow of a QScrollBar.
3799
3800 \row
3801 \li \c ::left-corner \target left-corner-sub
3802 \li The left corner of a QTabWidget. For example, this control can be
3803 used to control position the left corner widget in a QTabWidget.
3804
3805 \row
3806 \li \c ::menu-arrow \target menu-arrow-sub
3807 \li The arrow of a QToolButton with a menu.
3808
3809 \row
3810 \li \c ::menu-button \target menu-button-sub
3811 \li The menu button of a QToolButton.
3812
3813 \row
3814 \li \c ::menu-indicator \target menu-indicator-sub
3815 \li The menu indicator of a QPushButton.
3816
3817 \row
3818 \li \c ::right-arrow \target right-arrow-sub
3819 \li The right arrow of a QMenu or a QScrollBar.
3820
3821 \row
3822 \li \c ::pane \target pane-sub
3823 \li The pane (frame) of a QTabWidget.
3824
3825 \row
3826 \li \c ::right-corner \target right-corner-sub
3827 \li The right corner of a QTabWidget. For example, this control can be
3828 used to control the position the right corner widget in a QTabWidget.
3829
3830 \row
3831 \li \c ::scroller \target scroller-sub
3832 \li The scroller of a QMenu or QTabBar.
3833
3834 \row
3835 \li \c ::section \target section-sub
3836 \li The section of a QHeaderView.
3837
3838 \row
3839 \li \c ::separator \target separator-sub
3840 \li The separator of a QMenu or in a QMainWindow.
3841
3842 \row
3843 \li \c ::sub-line \target sub-line-sub
3844 \li The button to subtract a line of a QScrollBar.
3845
3846 \row
3847 \li \c ::sub-page \target sub-page-sub
3848 \li The region between the handle (slider) and the \l{#sub-line-sub}{sub-line}
3849 of a QScrollBar.
3850
3851 \row
3852 \li \c ::tab \target tab-sub
3853 \li The tab of a QTabBar or QToolBox.
3854
3855 \row
3856 \li \c ::tab-bar \target tab-bar-sub
3857 \li The tab bar of a QTabWidget. This subcontrol exists only to
3858 control the position of the QTabBar inside the QTabWidget. To
3859 style the tabs using the \l{#tab-sub}{::tab} subcontrol.
3860
3861 \row
3862 \li \c ::tear \target tear-sub
3863 \li The tear indicator of a QTabBar.
3864
3865 \row
3866 \li \c ::tearoff \target tearoff-sub
3867 \li The tear-off indicator of a QMenu.
3868
3869 \row
3870 \li \c ::text \target text-ps
3871 \li The text of a QAbstractItemView.
3872
3873 \row
3874 \li \c ::title \target title-sub
3875 \li The title of a QGroupBox or a QDockWidget.
3876
3877 \row
3878 \li \c ::up-arrow \target up-arrow-sub
3879 \li The up arrow of a QHeaderView (sort indicator), QScrollBar
3880 or a QSpinBox.
3881
3882 \row
3883 \li \c ::up-button \target up-button-sub
3884 \li The up button of a QSpinBox.
3885
3886 \endtable
3887
3888 See \l{Customizing the QPushButton's Menu Indicator Sub-Control}
3889 for an example of how to customize a subcontrol.
3890 */
3891
3892/*!
3893 \page stylesheet-examples.html
3894 \previouspage Qt Style Sheets Reference
3895 \title Qt Style Sheets Examples
3896
3897 We will now see a few examples to get started with using Qt Style Sheets.
3898
3899 \section1 Style Sheet Usage
3900
3901 \section2 Customizing the Foreground and Background Colors
3902
3903 Let's start by setting yellow as the background color of all
3904 \l{QLineEdit}s in an application. This could be achieved like
3905 this:
3906
3907 \snippet code/doc_src_stylesheet.cpp 88
3908
3909 If we want the property to apply only to the \l{QLineEdit}s that are
3910 children (or grandchildren or grand-grandchildren) of a specific dialog,
3911 we would rather do this:
3912
3913 \snippet code/doc_src_stylesheet.cpp 89
3914
3915 If we want the property to apply only to one specific QLineEdit,
3916 we can give it a name using QObject::setObjectName() and use an
3917 ID Selector to refer to it:
3918
3919 \snippet code/doc_src_stylesheet.cpp 90
3920
3921 Alternatively, we can set the
3922 \l{Qt Style Sheets Reference#background-prop}{background-color} property directly on the
3923 QLineEdit, omitting the selector:
3924
3925 \snippet code/doc_src_stylesheet.cpp 91
3926
3927 To ensure a good contrast, we should also specify a suitable
3928 color for the text:
3929
3930 \snippet code/doc_src_stylesheet.cpp 92
3931
3932 It might be a good idea to change the colors used for selected
3933 text as well:
3934
3935 \snippet code/doc_src_stylesheet.cpp 93
3936
3937
3938 \section2 Customizing Using Dynamic Properties
3939
3940 There are many situations where we need to present a form that
3941 has mandatory fields. To indicate to the user that the field is
3942 mandatory, one effective (albeit esthetically dubious) solution
3943 is to use yellow as the background color for those fields. It
3944 turns out this is very easy to implement using Qt Style Sheets.
3945 First, we would use the following application-wide style sheet:
3946
3947 \snippet code/doc_src_stylesheet.qdoc 94
3948
3949 This means that every widget whose \c mandatoryField Qt property
3950 is set to true would have a yellow background.
3951
3952 Then, for each mandatory field widget, we would simply create a
3953 \c mandatoryField property on the fly and set it to true. For
3954 example:
3955
3956 \snippet code/doc_src_stylesheet.cpp 95
3957
3958 \section2 Customizing a QPushButton Using the Box Model
3959
3960 This time, we will show how to create a red QPushButton. This
3961 QPushButton would presumably be connected to a very destructive
3962 piece of code.
3963
3964 First, we are tempted to use this style sheet:
3965
3966 \snippet code/doc_src_stylesheet.qdoc 96
3967
3968 However, the result is a boring, flat button with no borders:
3969
3970 \image stylesheet-redbutton1.png {Flat red button}
3971
3972 What happened is this:
3973
3974 \list
3975 \li We have made a request that cannot be satisfied using the
3976 native styles alone (e.g., the Windows Vista theme engine doesn't
3977 let us specify the background color of a button).
3978 \li Therefore, the button is rendered using style sheets.
3979 \li We haven't specified any values for
3980 \l{Qt Style Sheets Reference#border-width-prop}{border-width} and
3981 \l{Qt Style Sheets Reference#border-style-prop}{border-style}, so by default we obtain
3982 a 0-pixel wide border of style \c none.
3983 \endlist
3984
3985 Let's improve the situation by specifying a border:
3986
3987 \snippet code/doc_src_stylesheet.qdoc 97
3988
3989 \image stylesheet-redbutton2.png {Red button with a beige border}
3990
3991 Things look already a lot better. But the button looks a bit
3992 cramped. Let's specify some spacing between the border and the
3993 text using the \l{Qt Style Sheets Reference#padding-prop}{padding}. Additionally, we will
3994 enforce a minimum width, round the corners, and specify a larger
3995 font to make the button look nicer:
3996
3997 \snippet code/doc_src_stylesheet.qdoc 98
3998
3999 \image stylesheet-redbutton3.png
4000 {Red button with a round beige border and big, bold text}
4001
4002 The only issue remaining is that the button doesn't react when we
4003 press it. We can fix this by specifying a slightly different
4004 background color and use a different border style.
4005
4006 \snippet code/doc_src_stylesheet.qdoc 99
4007
4008 \section2 Customizing the QPushButton's Menu Indicator Sub-Control
4009
4010 Subcontrols give access to the sub-elements of a widget. For
4011 example, a QPushButton associated with a menu (using
4012 QPushButton::setMenu()) has a menu indicator. Let's customize
4013 the menu indicator for the red push button:
4014
4015 \snippet code/doc_src_stylesheet.qdoc 100
4016
4017 By default, the menu indicator is located at the bottom-right
4018 corner of the padding rectangle. We can change this by specifying
4019 \l{Qt Style Sheets Reference#subcontrol-position-prop}{subcontrol-position} and
4020 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin} to anchor the
4021 indicator differently. We can also use \l{Qt Style Sheets Reference#top-prop}{top} and
4022 \l{Qt Style Sheets Reference#left-prop}{left} to move the indicator by a few pixels. For
4023 example:
4024
4025 \snippet code/doc_src_stylesheet.qdoc 101
4026
4027 This positions the \c myindicator.png to the center right of the
4028 QPushButton's \l{Qt Style Sheets Reference#padding-prop}{padding} rectangle (see
4029 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin} for more
4030 information).
4031
4032 \section2 Complex Selector Example
4033
4034 Since red seems to be our favorite color, let's make the text in
4035 QLineEdit red by setting the following application-wide
4036 stylesheet:
4037
4038 \snippet code/doc_src_stylesheet.qdoc 102
4039
4040 However, we would like to give a visual indication that a
4041 QLineEdit is read-only by making it appear gray:
4042
4043 \snippet code/doc_src_stylesheet.qdoc 103
4044
4045 At some point, our design team comes with the requirement that
4046 all \l{QLineEdit}s in the registration form (with the
4047 \l{QObject::objectName}{object name} \c registrationDialog) to be
4048 brown:
4049
4050 \snippet code/doc_src_stylesheet.qdoc 104
4051
4052 A few UI design meetings later, we decide that all our
4053 \l{QDialog}s should have brown colored \l{QLineEdit}s:
4054
4055 \snippet code/doc_src_stylesheet.qdoc 105
4056
4057 Quiz: What happens if we have a read-only QLineEdit in a QDialog?
4058 [Hint: The \l{The Style Sheet Syntax#Conflict Resolution}{Conflict Resolution} section above explains
4059 what happens in cases like this.]
4060
4061 \section1 Customizing Specific Widgets
4062
4063 This section provides examples to customize specific widgets using Style Sheets.
4064
4065 \section2 Customizing QAbstractScrollArea
4066
4067 The background of any QAbstractScrollArea (Item views, QTextEdit
4068 and QTextBrowser) can be set using the background properties. For example,
4069 to set a background-image that scrolls with the scroll bar:
4070 \snippet code/doc_src_stylesheet.qdoc 106
4071
4072 If the background-image is to be fixed with the viewport:
4073 \snippet code/doc_src_stylesheet.qdoc 107
4074
4075 \section2 Customizing QCheckBox
4076
4077 Styling of a QCheckBox is almost identical to styling a QRadioButton. The
4078 main difference is that a tristate QCheckBox has an indeterminate state.
4079
4080 \snippet code/doc_src_stylesheet.qdoc 108
4081
4082 \section2 Customizing QComboBox
4083
4084 We will look at an example where the drop down button of a QComboBox
4085 appears "merged" with the combo box frame.
4086
4087 \snippet code/doc_src_stylesheet.qdoc 109
4088
4089 The pop-up of the QComboBox is a QAbstractItemView and is styled using
4090 the descendant selector:
4091 \snippet code/doc_src_stylesheet.qdoc 110
4092
4093 \section2 Customizing QDockWidget
4094
4095 The title bar and the buttons of a QDockWidget can be customized as
4096 follows:
4097
4098 \snippet code/doc_src_stylesheet.qdoc 111
4099
4100 If one desires to move the dock widget buttons to the left, the following
4101 style sheet can be used:
4102
4103 \snippet code/doc_src_stylesheet.qdoc 112
4104
4105 \note To customize the separator (resize handle) of a QDockWidget,
4106 use QMainWindow::separator.
4107
4108 \section2 Customizing QFrame
4109
4110 A QFrame is styled using the \l{The Box Model}.
4111
4112 \snippet code/doc_src_stylesheet.qdoc 113
4113
4114 \section2 Customizing QGroupBox
4115
4116 Let us look at an example that moves the QGroupBox's title to
4117 the center.
4118
4119 \snippet code/doc_src_stylesheet.qdoc 114
4120
4121 For a checkable QGroupBox, use the \{#indicator-sub}{::indicator} subcontrol
4122 and style it exactly like a QCheckBox (i.e)
4123
4124 \snippet code/doc_src_stylesheet.qdoc 115
4125
4126 \section2 Customizing QHeaderView
4127
4128 QHeaderView is customized as follows:
4129
4130 \snippet code/doc_src_stylesheet.qdoc 116
4131
4132 \section2 Customizing QLineEdit
4133
4134 The frame of a QLineEdit is styled using the \l{The Box Model}. To
4135 create a line edit with rounded corners, we can set:
4136 \snippet code/doc_src_stylesheet.qdoc 117
4137
4138 The password character of line edits that have QLineEdit::Password
4139 echo mode can be set using:
4140 \snippet code/doc_src_stylesheet.qdoc 118
4141
4142 The background of a read only QLineEdit can be modified as below:
4143 \snippet code/doc_src_stylesheet.qdoc 119
4144
4145 \section2 Customizing QListView
4146
4147 The background color of alternating rows can be customized using the following
4148 style sheet:
4149
4150 \snippet code/doc_src_stylesheet.qdoc 120
4151
4152 To provide a special background when you hover over items, we can use the
4153 \l{item-sub}{::item} subcontrol. For example,
4154
4155 \snippet code/doc_src_stylesheet.qdoc 121
4156
4157 \section2 Customizing QMainWindow
4158
4159 The separator of a QMainWindow can be styled as follows:
4160
4161 \snippet code/doc_src_stylesheet.qdoc 122
4162
4163 \section2 Customizing QMenu
4164
4165 Individual items of a QMenu are styled using the 'item' subcontrol as
4166 follows:
4167
4168 \snippet code/doc_src_stylesheet.qdoc 123
4169
4170 For a more advanced customization, use a style sheet as follows:
4171
4172 \snippet code/doc_src_stylesheet.qdoc 124
4173
4174 \section2 Customizing QMenuBar
4175
4176 QMenuBar is styled as follows:
4177
4178 \snippet code/doc_src_stylesheet.qdoc 125
4179
4180 \section2 Customizing QProgressBar
4181
4182 The QProgressBar's \l{stylesheet-reference.html#border-prop}{border},
4183 \l{stylesheet-reference.html#chunk-sub}{chunk}, and
4184 \l{stylesheet-reference.html#text-align-prop}{text-align} can be customized using
4185 style sheets. However, if one property or sub-control is customized,
4186 all the other properties or sub-controls must be customized as well.
4187
4188 \image progressBar-stylesheet.png {Progress bar showing 30%}
4189
4190 For example, we change the \l{stylesheet-reference.html#border-prop}
4191 {border} to grey and the \l{stylesheet-reference.html#chunk-sub}{chunk}
4192 to cerulean.
4193
4194 \snippet code/doc_src_stylesheet.qdoc 126
4195
4196 This leaves the \l{stylesheet-reference.html#text-align-prop}
4197 {text-align}, which we customize by positioning the text in the center of
4198 the progress bar.
4199
4200 \snippet code/doc_src_stylesheet.qdoc 127
4201
4202 A \l{stylesheet-reference.html#margin-prop}{margin} can be included to
4203 obtain more visible chunks.
4204
4205 \image progressBar2-stylesheet.png {Notched progress bar}
4206
4207 In the screenshot above, we use a
4208 \l{stylesheet-reference.html#margin-prop}{margin} of 0.5 pixels.
4209
4210 \snippet code/doc_src_stylesheet.qdoc 128
4211
4212 \section2 Customizing QPushButton
4213
4214 A QPushButton is styled as follows:
4215 \snippet code/doc_src_stylesheet.qdoc 129
4216
4217 For a QPushButton with a menu, use the
4218 \l{Qt Style Sheets Reference#menu-indicator-sub}{::menu-indicator}
4219 subcontrol.
4220
4221 \snippet code/doc_src_stylesheet.qdoc 130
4222
4223 Checkable QPushButton have the \l{Qt Style Sheets Reference#checked-ps}
4224 {:checked} pseudo state set.
4225
4226 \section2 Customizing QRadioButton
4227
4228 The indicator of a QRadioButton can be changed using:
4229 \snippet code/doc_src_stylesheet.qdoc 131
4230
4231 \section2 Customizing QScrollBar
4232
4233 The QScrollBar can be styled using its subcontrols like
4234 \l{stylesheet-reference.html#handle-sub}{handle},
4235 \l{stylesheet-reference.html#add-line-sub}{add-line},
4236 \l{stylesheet-reference.html#sub-line-sub}{sub-line}, and so on. Note that
4237 if one property or sub-control is customized, all the other properties or
4238 sub-controls must be customized as well.
4239
4240 \image stylesheet-scrollbar1.png {Green stylized scroll bar}
4241
4242 The scroll bar above has been styled in aquamarine with a solid grey
4243 border.
4244
4245 \snippet code/doc_src_stylesheet.qdoc 132
4246
4247 \snippet code/doc_src_stylesheet.qdoc 133
4248
4249 \snippet code/doc_src_stylesheet.qdoc 134
4250
4251 The \l{stylesheet-reference.html#left-arrow-sub}{left-arrow} and
4252 \l{stylesheet-reference.html#right-arrow-sub}{right-arrow} have a solid grey
4253 border with a white background. As an alternative, you could also embed the
4254 image of an arrow.
4255
4256 \snippet code/doc_src_stylesheet.qdoc 135
4257
4258 If you want the scroll buttons of the scroll bar to be placed together
4259 (instead of the edges) like on \macos, you can use the following
4260 stylesheet:
4261 \snippet code/doc_src_stylesheet.qdoc 136
4262
4263 The scroll bar using the above stylesheet looks like this:
4264 \image stylesheet-scrollbar2.png {Colorized scroll bar}
4265
4266
4267 To customize a vertical scroll bar use a style sheet similar to the following:
4268 \snippet code/doc_src_stylesheet.qdoc 137
4269
4270 \section2 Customizing QSizeGrip
4271
4272 QSizeGrip is usually styled by just setting an image.
4273
4274 \snippet code/doc_src_stylesheet.qdoc 138
4275
4276 \section2 Customizing QSlider
4277
4278 You can style horizontal slider as below:
4279 \snippet code/doc_src_stylesheet.qdoc 139
4280
4281 If you want to change the color of the slider parts before and after the handle, you can use the add-page
4282 and sub-page subcontrols. For example, for a vertical slider:
4283
4284 \snippet code/doc_src_stylesheet.qdoc 140
4285
4286 \section2 Customizing QSpinBox
4287
4288 QSpinBox can be completely customized as below (the style sheet has commentary inline):
4289
4290 \snippet code/doc_src_stylesheet.qdoc 141
4291
4292
4293 \section2 Customizing QSplitter
4294
4295 A QSplitter derives from a QFrame and hence can be styled like a QFrame.
4296 The grip or the handle is customized using the
4297 \l{Qt Style Sheets Reference#handle-sub}{::handle} subcontrol.
4298
4299 \snippet code/doc_src_stylesheet.qdoc 142
4300
4301 \section2 Customizing QStatusBar
4302
4303 We can provide a background for the status bar and a border for items
4304 inside the status bar as follows:
4305 \snippet code/doc_src_stylesheet.qdoc 143
4306
4307 Note that widgets that have been added to the QStatusBar can be styled
4308 using the descendant declaration (i.e)
4309 \snippet code/doc_src_stylesheet.qdoc 144
4310
4311 \section2 Customizing QTabWidget and QTabBar
4312
4313 \image tabWidget-stylesheet1.png {Image of several tabs}
4314
4315 For the screenshot above, we need a stylesheet as follows:
4316
4317 \snippet code/doc_src_stylesheet.qdoc 145
4318
4319 Often we require the tabs to overlap to look like below:
4320 \image tabWidget-stylesheet2.png {Image of overlapped tabs}
4321
4322 For a tab widget that looks like above, we make use of
4323 \l{https://doc.qt.io/qt-5/stylesheet-customizing.html#the-box-model}
4324 {negative margins}. Negative values draw the element closer to its
4325 neighbors than it would be by default. The resulting stylesheet
4326 looks like this:
4327
4328 \snippet code/doc_src_stylesheet.qdoc 146
4329
4330 To move the tab bar to the center (as below), we require the following stylesheet:
4331 \image tabWidget-stylesheet3.png {Several tabs centered in the widget}
4332
4333 \snippet code/doc_src_stylesheet.qdoc 147
4334
4335 The tear indicator and the scroll buttons can be further customized as follows:
4336 \snippet code/doc_src_stylesheet.qdoc 148
4337
4338 Since Qt 4.6 the close button can be customized as follow:
4339 \snippet code/doc_src_stylesheet.qdoc 159
4340
4341 \section2 Customizing QTableView
4342
4343 Suppose we'd like our selected item in QTableView to have bubblegum pink
4344 fade to white as its background.
4345
4346 \image tableWidget-stylesheet.png {Table view with custom style}
4347
4348 This is possible with the
4349 \l{stylesheet-reference.html#selection-background-color-prop}
4350 {selection-background-color} property and the syntax required is:
4351
4352 \snippet code/doc_src_stylesheet.qdoc 149
4353
4354 The corner widget can be customized using the following style sheet
4355
4356 \snippet code/doc_src_stylesheet.qdoc 150
4357
4358 The QTableView's checkbox indicator can also be customized. In the
4359 following snippet the indicator \c background-color in unchecked state is
4360 customized:
4361
4362 \snippet code/doc_src_stylesheet.qdoc 161
4363
4364 \section2 Customizing QToolBar
4365
4366 The background and the handle of a QToolBar is customized as below:
4367 \snippet code/doc_src_stylesheet.qdoc 151
4368
4369 \section2 Customizing QToolBox
4370
4371 The tabs of the QToolBox are customized using the 'tab' subcontrol.
4372
4373 \snippet code/doc_src_stylesheet.qdoc 152
4374
4375 \section2 Customizing QToolButton
4376
4377 There are three types of QToolButtons.
4378 \list
4379 \li The QToolButton has no menu. In this case, the QToolButton is styled
4380 exactly like QPushButton. See
4381 \l{#Customizing QPushButton}{Customizing QPushButton} for an
4382 example.
4383
4384 \li The QToolButton has a menu and has the QToolButton::popupMode set to
4385 QToolButton::DelayedPopup or QToolButton::InstantPopup. In this case,
4386 the QToolButton is styled exactly like a QPushButton with a menu.
4387 See \l{#Customizing QPushButton}{Customizing QPushButton} for an
4388 example of the usage of the menu-indicator pseudo state.
4389
4390 \li The QToolButton has its QToolButton::popupMode set to
4391 QToolButton::MenuButtonPopup. In this case, we style it as follows:
4392 \endlist
4393
4394 \snippet code/doc_src_stylesheet.qdoc 153
4395
4396
4397 \section2 Customizing QToolTip
4398
4399 QToolTip is customized exactly like a QLabel. In addition, for platforms
4400 that support it, the opacity property may be set to adjust the opacity.
4401
4402 For example,
4403 \snippet code/doc_src_stylesheet.qdoc 154
4404
4405 \section2 Customizing QTreeView
4406
4407 The background color of alternating rows can be customized using the following
4408 style sheet:
4409
4410 \snippet code/doc_src_stylesheet.qdoc 155
4411
4412 To provide a special background when you hover over items, we can use the
4413 \l{item-sub}{::item} subcontrol. For example,
4414 \snippet code/doc_src_stylesheet.qdoc 156
4415
4416 The branches of a QTreeView are styled using the
4417 \l{Qt Style Sheets Reference#branch-sub}{::branch} subcontrol. The
4418 following stylesheet color codes the various states when drawing
4419 a branch.
4420
4421 \snippet code/doc_src_stylesheet.qdoc 157
4422
4423 Colorful, though it is, a more useful example can be made using the
4424 following images:
4425
4426 \table
4427 \row
4428 \li \inlineimage stylesheet-vline.png {Vertical line}
4429 \li \inlineimage stylesheet-branch-more.png {Junction line for lists}
4430 \li \inlineimage stylesheet-branch-end.png {Line for terminating the list}
4431 \li \inlineimage stylesheet-branch-closed.png {Arrow pointing right}
4432 \li \inlineimage stylesheet-branch-open.png {Arrow pointing down}
4433 \row
4434 \li vline.png
4435 \li branch-more.png
4436 \li branch-end.png
4437 \li branch-closed.png
4438 \li branch-open.png
4439 \endtable
4440
4441 \snippet code/doc_src_stylesheet.qdoc 158
4442
4443 The resulting tree view looks like this:
4444
4445 \image stylesheet-treeview.png {Tree view with styled branches}
4446
4447 \sa {Supported HTML Subset}, QStyle
4448
4449
4450 \section1 Common Mistakes
4451
4452 This section lists some common mistakes when using stylesheets.
4453
4454 \section2 QPushButton and images
4455
4456 When styling a QPushButton, it is often desirable to use an image as the
4457 button graphic. It is common to try the
4458 \l{Qt Style Sheets Reference#background-image-prop}{background-image}
4459 property,
4460 but this has a number of drawbacks: For instance, the background will
4461 often appear hidden behind the button decoration, because it is not
4462 considered a background. In addition, if the button is resized, the
4463 entire background will be stretched or tiled, which does not
4464 always look good.
4465
4466 It is better to use the
4467 \l{Qt Style Sheets Reference#border-image-prop}{border-image}
4468 property, as it will always display the image,
4469 regardless of the background (you can combine it with a background if it
4470 has alpha values in it), and it has special settings to deal with button
4471 resizing.
4472
4473 Consider the following snippet:
4474
4475 \snippet stylesheet/common-mistakes.cpp 1
4476
4477 This will produce a button looking like this:
4478
4479 \image stylesheet-border-image-normal.png {Button with a background}
4480
4481 The numbers after the url gives the top, right, bottom and left number of
4482 pixels, respectively. These numbers correspond to the border and should not
4483 stretch when the size changes.
4484 Whenever you resize the button, the middle part of the image will stretch
4485 in both directions, while the pixels specified in the stylesheet
4486 will not. This makes the borders of the button look more natural, like
4487 this:
4488
4489 \image stylesheet-border-image-stretched.png
4490 {Button with specified border sizes}
4491 \caption With borders
4492
4493 \image stylesheet-border-image-wrong.png
4494 {Button without specified border sizes}
4495 \caption Without borders
4496
4497 */