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
qtlabsstylekit-overview.qdoc
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page qtlabsstylekit-overview-features.html
6 \title StyleKit Features Overview
7 \brief An introduction to the main features of StyleKit.
8
9 This page gives a brief introduction to the main features of StyleKit.
10 For a complete reference of all available types and properties, see the
11 \l {Qt Labs StyleKit QML Types}{QML Types} page.
12
13 \section1 Creating a Style
14
15 A \l Style is a QML object that describes the visual appearance of all
16 \l {Qt Quick Controls} in your application — \l {StylableControls::}{button},
17 \l {StylableControls::}{slider}, \l {StylableControls::}{checkBox}, and
18 so on. Each has its own group in the style where you can set properties such as
19 colors, sizes, radii, and shadows for the visual parts that make up the control.
20
21 The \l {StylableControls::control}{control group} is special, since it acts as
22 a fallback for all the other control groups. If you leave out some of the properties
23 for a \c slider, for example, they will be read from \c control instead.
24 Properties not set in \c slider or \c control fall back further to the
25 \l {Style::fallbackStyle}{fallback style} which is a complete style similar to
26 the \l {Basic Style}.
27 This means you don't necessarily need to style all the available controls, only
28 the ones you want to customize — the fallback system takes care of styling the rest:
29
30 \snippet Overview_style.qml Plain Style
31
32 \section2 Activating a Style
33
34 To activate the style, assign it to \l {StyleKit::style}{StyleKit.style} on
35 the root \l ApplicationWindow. All controls in the application then pick it up
36 automatically:
37
38 \snippet PlainStyleMain.qml 1
39
40 \section1 Control States
41
42 Controls change appearance depending on user interaction — a button looks
43 different when hovered, pressed, or disabled. \c StyleKit lets you express
44 this in the style by placing the \l {ControlStateStyle}{state} name in front of
45 the affected properties, to give them alternative values when the control is
46 in that state.
47
48 States can be nested, and a more specific combination (e.g.
49 \c hovered.checked) takes precedence over its individual components:
50
51 \snippet Overview_states.qml States
52
53 \section2 State Transitions
54
55 State changes can be animated by setting the
56 \l {ControlStyle::transition}{transition} property on a control style.
57 A \l StyleAnimation provides a convenient way to animate groups of
58 related style properties, such as all background or indicator colors, but
59 you can use standard QML animations such as \l {ColorAnimation} and
60 \l {NumberAnimation} as well:
61
62 \snippet StyleAnimationSnippets.qml transition
63
64 \section1 Theming
65
66 \c StyleKit has built-in support for light and dark themes through the
67 \l {Style::light}{light} and \l {Style::dark}{dark} properties on a \l Style.
68 Similar to a \l Style, a \l Theme lets you define the style each control
69 should have when that theme is active. Properties that are not set in a
70 theme will fall back to be read from the style:
71
72 \snippet Overview_theme.qml themes
73
74 \section2 Custom Themes
75
76 Beyond light and dark, you can define any number of additional themes using
77 \l CustomTheme. Each \c CustomTheme has a \l {CustomTheme::name}{name} and
78 holds a \l Theme object with the same structure as the built-in themes:
79
80 \snippet CustomThemeSnippets.qml custom themes
81
82 To switch themes at runtime, set \l {Style::themeName}{Style.themeName} from
83 a QML file in your application to the name of the desired theme. The
84 \l {Style::availableThemeNames}{Style.availableThemeNames} property lists
85 all available theme names, which makes it straightforward to populate a
86 selector control:
87
88 \snippet CustomThemeSnippets.qml change theme
89
90 To activate a theme at application start-up, set
91 \l {Style::themeName}{themeName} when assigning the style:
92
93 \snippet CustomThemeSnippets.qml custom theme at start-up
94
95 \section1 Style Variations
96
97 A \l StyleVariation lets you define alternative styling for parts of the
98 application. This is useful when you need to style controls differently when
99 they are children of, for example, a ToolBar or a GroupBox, or if you want
100 to implement style hints that the application can optionally apply to some
101 of the controls.
102
103 There are two types of style variations: type variations and instance variations.
104
105 \section2 Type Variations
106
107 A type variation contains alternative styling for controls that are children
108 (or descendants) of another control type. This means that if a StyleVariation
109 contains styling for a button, and it's added to the \l {ControlStyle::variations}{variations}
110 property of a frame, \c StyleKit will style all \l [QtQuickControls]{Button}{Buttons} that
111 are children of \l [QtQuickControls]{Frame}{Frames} in the application accordingly:
112
113 \snippet TypeVariationSnippets.qml frame with variation
114
115 \section2 Instance Variations
116
117 Named \l {StyleVariation}{StyleVariations} can be applied to individual controls
118 in the application using the \l {StyleVariation::variations}{StyleVariation.variations}
119 attached property. When applied, the control itself, and all its descendants, will
120 receive the alternative styling. This is different from a type variation, which
121 affects all controls of a certain type, such as all \l [QtQuickControls]{Frame}{Frames}.
122 Instance variations will only affect the control instance (and the descendants) on which
123 they're attached:
124
125 \snippet InstanceVariationSnippets.qml instance variations in style
126
127 Apply them to controls in your application:
128
129 \snippet InstanceVariationSnippets.qml apply instance variation
130
131 \section1 Custom Controls
132
133 If your application includes custom controls that are not part of
134 \l {Qt Quick Controls}, you can still integrate them with \c StyleKit.
135 Just add a \l CustomControl for each of them and style them the same
136 way you style the \l {StylableControls}{built-in controls}:
137
138 \snippet CustomControlSnippets.qml custom control style
139
140 In the control's implementation, use a \l StyleReader with the matching
141 \l {StyleReader::controlType}{controlType} to read back the style properties.
142 The correct property values are resolved by taking \l {Theme}{Themes},
143 \l {StyleVariation}{StyleVariations}, \l {StylableControls}{fallback types},
144 and property propagation into account.
145 For a style reader to do this, it needs to know the state of your control.
146 Therefore bind your control's state to the relevant \l StyleReader
147 properties such as \l {StyleReader::hovered}{hovered} and
148 \l {StyleReader::pressed}{pressed}. Each time there is a state change, any
149 affected style properties will be updated, causing your control to repaint:
150
151 \snippet CustomControlSnippets.qml custom control
152
153 \section1 Custom Delegates
154
155 Each visual part of a control —
156 \l {ControlStyleProperties::background}{background},
157 \l {ControlStyleProperties::handle}{handle},
158 \l {ControlStyleProperties::indicator}{indicator}, etc — is rendered by a
159 \l {DelegateStyle::delegate}{delegate}. By default \c StyleKit uses
160 \l StyledItem for rendering, but you can replace it entirely with you own
161 QML component.
162
163 The component needs to define two \l {Required Properties}{required properties}
164 that \c StyleKit populates automatically:
165
166 \list
167 \li \c delegateStyle — the \l DelegateStyle that carries the resolved style
168 properties (color, radius, implicit size, etc.)
169 \li \c control — the \l {Qt Quick Controls}{Qt Quick Control} the delegate belongs to
170 \endlist
171
172 You then assign the component to the \l {DelegateStyle::delegate}{delegate} property
173 of the visual part that you want to affect:
174
175 \snippet DelegateStyle_delegates.qml delegate
176
177 \section2 Overlay and Underlay
178
179 If you only want to \e augment the default rendering rather than replace it
180 completely, use \l StyledItem as the root of your delegate. Any children you
181 add to \l StyledItem are drawn on top of (overlay) the default rendering:
182
183 \snippet StyledItemOverlay.qml overlay
184
185 To draw something \e underneath the default rendering instead, make your
186 delegate an \l Item, place the extra content first, and embed a \l StyledItem
187 as a child to render the default appearance on top:
188
189 \snippet StyledItemUnderlay.qml underlay
190
191 \section2 Custom Data
192
193 Custom delegates sometimes need additional styling properties that go beyond the
194 \l {DelegateStyle}{built-in ones} — for example to style child items
195 that \c StyleKit knows nothing about. The \l {DelegateStyle::data}{data}
196 property makes this possible. It can hold any \l QtObject, so it can carry
197 whatever information your delegate needs.
198
199 Like all the other style properties, \c data participates in style property
200 resolution — the delegate always receives the object that matches the current
201 control state, active theme, and style variations. Unlike the built-in
202 properties, \c data is propagated as a whole — individual properties \e inside
203 the object do not propagate separately:
204
205 \snippet DelegateStyle_delegates.qml data
206
207*/