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