Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
stylesheet-customizing.qdoc
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page stylesheet-customizing.html
6 \previouspage Qt Widgets Designer Integration
7 \nextpage Qt Style Sheets Reference
8 \title Customizing Qt Widgets Using Style Sheets
9
10 When using style sheets, every widget is treated as a box with four
11 concentric rectangles: the margin rectangle, the border rectangle, the
12 padding rectangle, and the content rectangle. The box model describes
13 this in further detail.
14
15 \target box model
16 \section1 The Box Model
17
18 The four concentric rectangles appear conceptually as below:
19
20 \image stylesheet-boxmodel.png
21 {Diagram of the CSS box model for layout design}
22
23 \list
24 \li The margin falls outside the border.
25 \li The border is drawn between the margin and the padding.
26 \li The padding falls inside the border, between the border and
27 the actual contents.
28 \li The content is what is left from the original widget or
29 subcontrol once we have removed the margin, the border, and
30 the padding.
31 \endlist
32
33 The \l{Qt Style Sheets Reference#margin-prop}{margin},
34 \l{Qt Style Sheets Reference#border-width-prop}
35 {border-width}, and
36 \l{Qt Style Sheets Reference#padding-prop}{padding}
37 properties all default to zero. In that case, all four rectangles
38 (\c margin, \c border, \c padding, and \c content) coincide exactly.
39
40 You can specify a background for the widget using the
41 \l{Qt Style Sheets Reference#background-image-prop}{background-image}
42 property. By default, the background-image is drawn only for the area
43 inside the border. This can be changed using the
44 \l{Qt Style Sheets Reference#background-clip-prop}{background-clip}
45 property. You can use
46 \l{Qt Style Sheets Reference#background-repeat-prop}{background-repeat}
47 and
48 \l{Qt Style Sheets Reference#background-origin-prop}{background-origin}
49 to control the repetition and origin of the background image.
50
51 A background-image does not scale with the size of the widget. To provide
52 a "skin" or background that scales along with the widget size, one must
53 use
54 \l{Qt Style Sheets Reference#border-image-prop}{border-image}. Since the
55 border-image property provides an alternate background, it is not required
56 to specify a background-image when border-image is specified. In the case,
57 when both of them are specified, the border-image draws over the
58 background-image.
59
60 In addition, the \l{Qt Style Sheets Reference#image-prop}{image} property
61 may be used to draw an image over the border-image. The image specified does
62 not tile or stretch and when its size does not match the size of the widget,
63 its alignment is specified using the
64 \l{Qt Style Sheets Reference#image-position-prop}{image-position}
65 property. Unlike background-image and border-image, one may specify a
66 SVG in the image property, in which case the image is scaled automatically
67 according to the widget size.
68
69 The steps to render a rule are as follows:
70 \list
71 \li Set clip for entire rendering operation (border-radius)
72 \li Draw the background (background-image)
73 \li Draw the border (border-image, border)
74 \li Draw overlay image (image)
75 \endlist
76
77 \target sub controls
78 \section1 Sub-controls
79
80 A widget is considered as a hierarchy (tree) of subcontrols drawn on top
81 of each other. For example, the QComboBox draws the drop-down sub-control
82 followed by the down-arrow sub-control. A QComboBox is thus rendered as
83 follows:
84 \list
85 \li Render the QComboBox { } rule
86 \li Render the QComboBox::drop-down { } rule
87 \li Render the QComboBox::down-arrow { } rule
88 \endlist
89
90 Sub-controls share a parent-child relationship. In the case of QComboBox,
91 the parent of down-arrow is the drop-down and the parent of drop-down is
92 the widget itself. Sub-controls are positioned within their parent using
93 the \l{Qt Style Sheets Reference#subcontrol-position-prop}
94 {subcontrol-position} and
95 \l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}
96 properties.
97
98 Once positioned, sub-controls can be styled using the \l{box model}.
99
100 \note With complex widgets such as QComboBox and QScrollBar, if one
101 property or sub-control is customized, \b{all} the other properties or
102 sub-controls must be customized as well.
103
104*/