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