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 {AbstractStylableControls::}{button},
17 \l {AbstractStylableControls::}{slider}, \l {AbstractStylableControls::}{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 {AbstractStylableControls::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::themeNames}{Style.themeNames} property lists all available theme
85 names, which makes it straightforward to populate a selector control:
86
87 \snippet CustomThemeSnippets.qml change theme
88
89 To activate a theme at application start-up, set
90 \l {Style::themeName}{themeName} when assigning the style:
91
92 \snippet CustomThemeSnippets.qml custom theme at start-up
93
94 \section1 Style Variations
95
96 A \l StyleVariation lets you define alternative styling for parts of the
97 application. This is useful when you need to style controls differently when
98 they are children of, for example, a ToolBar or a GroupBox, or if you want
99 to implement style hints that the application can optionally apply to some
100 of the controls.
101
102 There are two types of style variations: type variations and instance variations.
103
104 \section2 Type Variations
105
106 A type variation contains alternative styling for controls that are children
107 (or descendants) of another control type. This means that if a StyleVariation
108 contains styling for a button, and it's added to the \l {ControlStyle::variations}{variations}
109 property of a frame, \c StyleKit will style all \l [QtQuickControls]{Button}{Buttons} that
110 are children of \l [QtQuickControls]{Frame}{Frames} in the application accordingly:
111
112 \snippet TypeVariationSnippets.qml frame with variation
113
114 \section2 Instance Variations
115
116 Named \l {StyleVariation}{StyleVariations} can be applied to individual controls
117 in the application using the \l {StyleVariation::variations}{StyleVariation.variations}
118 attached property. When applied, the control itself, and all its descendants, will
119 receive the alternative styling. This is different from a type variation, which
120 affects all controls of a certain type, such as all \l [QtQuickControls]{Frame}{Frames}.
121 Instance variations will only affect the control instance (and the descendants) on which
122 they're attached:
123
124 \snippet InstanceVariationSnippets.qml instance variations in style
125
126 Apply them to controls in your application:
127
128 \snippet InstanceVariationSnippets.qml apply instance variation
129
130 \section1 Custom Controls
131
132 If your application includes custom controls that are not part of
133 \l {Qt Quick Controls}, you can still integrate them with \c StyleKit.
134 Just add a \l CustomControl for each of them and style them the same
135 way you style the \l {AbstractStylableControls}{built-in controls}:
136
137 \snippet CustomControlSnippets.qml custom control style
138
139 In the control's implementation, use a \l StyleReader with the matching
140 \l {StyleReader::controlType}{controlType} to read back the style properties.
141 The correct property values are resolved by taking \l {Theme}{Themes},
142 \l {StyleVariation}{StyleVariations}, \l {AbstractStylableControls}{fallback types},
143 and property propagation into account.
144 For a style reader to do this, it needs to know the state of your control.
145 Therefore bind your control's state to the relevant \l StyleReader
146 properties such as \l {StyleReader::hovered}{hovered} and
147 \l {StyleReader::pressed}{pressed}. Each time there is a state change, any
148 affected style properties will be updated, causing your control to repaint:
149
150 \snippet CustomControlSnippets.qml custom control
151
152 \section1 Custom Delegates
153
154 Each visual part of a control —
155 \l {ControlStyleProperties::background}{background},
156 \l {ControlStyleProperties::handle}{handle},
157 \l {ControlStyleProperties::indicator}{indicator}, etc — is rendered by a
158 \l {DelegateStyle::delegate}{delegate}. By default \c StyleKit uses
159 \l StyledItem for rendering, but you can replace it entirely with you own
160 QML component.
161
162 The component needs to define two \l {Required Properties}{required properties}
163 that \c StyleKit populates automatically:
164
165 \list
166 \li \c delegateStyle — the \l DelegateStyle that carries the resolved style
167 properties (color, radius, implicit size, etc.)
168 \li \c control — the \l {Qt Quick Controls}{Qt Quick Control} the delegate belongs to
169 \endlist
170
171 You then assign the component to the \l {DelegateStyle::delegate}{delegate} property
172 of the visual part that you want to affect:
173
174 \snippet DelegateStyle_delegates.qml delegate
175
176 \section2 Overlay and Underlay
177
178 If you only want to \e augment the default rendering rather than replace it
179 completely, use \l StyledItem as the root of your delegate. Any children you
180 add to \l StyledItem are drawn on top of (overlay) the default rendering:
181
182 \snippet StyledItemOverlay.qml overlay
183
184 To draw something \e underneath the default rendering instead, make your
185 delegate an \l Item, place the extra content first, and embed a \l StyledItem
186 as a child to render the default appearance on top:
187
188 \snippet StyledItemUnderlay.qml underlay
189
190 \section2 Custom Data
191
192 Custom delegates sometimes need additional styling properties that go beyond the
193 \l {DelegateProperties}{built-in ones} — for example to style child items
194 that \c StyleKit knows nothing about. The \l {DelegateStyle::data}{data}
195 property makes this possible. It can hold any \l QtObject, so it can carry
196 whatever information your delegate needs.
197
198 Like all the other style properties, \c data participates in style property
199 resolution — the delegate always receives the object that matches the current
200 control state, active theme, and style variations. Unlike the built-in
201 properties, \c data is propagated as a whole — individual properties \e inside
202 the object do not propagate separately:
203
204 \snippet DelegateStyle_delegates.qml data
205
206*/