source: trunk/doc/src/widgets-and-layouts/stylesheet.qdoc@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

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