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