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
qtquickcontrols-customize.qdoc
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page qtquickcontrols-customize.html
6 \keyword Customizing Qt Quick Controls 2
7 \title Customizing Qt Quick Controls
8 \brief A set of UI controls to create user interfaces in Qt Quick
9
10 Qt Quick Controls consist of a hierarchy (tree) of items. In order to
11 provide a custom look and feel, the default QML implementation of each
12 item can be replaced with a custom one.
13
14 \section1 Customizing a Control
15
16 Sometimes you'll want to create a "one-off" look for a specific part of
17 your UI, and use a complete style everywhere else. Perhaps you're happy
18 with the style you're using, but there's a certain button that has some
19 special significance.
20
21 The first way to create this button is to simply define it in-place,
22 wherever it is needed. For example, perhaps you're not satisfied with the
23 Basic style's Button having square corners. To make them rounded, you
24 can override the \l {Control::}{background} item and set the radius
25 property of Rectangle:
26
27 \include customize-button-background.qdocinc file
28
29 \note as the different items that make up a control in any given style are
30 designed to work together, it may be necessary to override other items to
31 get the look you're after. In addition, not all styles can be customized.
32 See the note in \l {Customization Reference} for more information.
33
34 The second way to create the button is good if you plan to use your rounded
35 button in several places. It involves moving the code into its own QML file
36 within your project.
37
38 For this approach, we'll copy the background code from the Basic style's
39 \c Button.qml. This file can be found in the following path in your Qt
40 installation:
41
42 \c {$QTDIR/qml/QtQuick/Controls/Basic/Button.qml}
43
44 After doing that, we'll simply add the following line:
45
46 \code
47 radius: 4
48 \endcode
49
50 To avoid confusion with the controls in the
51 module itself, we'll call the file \c MyButton.qml. To use the control in
52 your application, refer to it by its filename:
53
54 \qml
55 import QtQuick.Controls.Basic
56
57 ApplicationWindow {
58 MyButton {
59 text: qsTr("A Special Button")
60 }
61 }
62 \endqml
63
64 The third way to create the button is a bit more structured, both in terms
65 of where the file sits in the file system and how it is used in QML. First,
66 copy an existing file as you did above, but this time, put it into a
67 subfolder in your project named (for example) \c controls. To use the
68 control, first import the folder into a namespace:
69
70 \qml
71 import QtQuick.Controls.Basic
72 import "controls" as MyControls
73
74 ApplicationWindow {
75 MyControls.Button {
76 text: qsTr("A Special Button")
77 }
78 }
79 \endqml
80
81 As you now have the \c MyControls namespace, you can name the controls after
82 their actual counterparts in the Qt Quick Controls module. You can repeat
83 this process for any control that you wish to add.
84
85 An added benefit of these three methods is that it's not necessary to
86 implement the template from scratch.
87
88 \note the three approaches mentioned here do not work for customizing the
89 attached \l ToolTip, as that is a shared item created internally. To do
90 a one-off customization of a \c ToolTip, see \l {Custom Tool Tips}. To
91 customize the attached \c ToolTip, it must be provided as part of
92 \l {Creating a Custom Style}{your own style}.
93
94 \section1 Creating a Custom Style
95
96 There are several ways to go about creating your own styles. Below, we'll
97 explain the various approaches.
98
99 \section2 Definition of a Style
100
101 In Qt Quick Controls, a style is essentially a set of QML files within a
102 single directory. There are four requirements for a style to be
103 \l {Using Styles in Qt Quick Controls}{usable}:
104
105 \list
106 \li At least one QML file whose name matches a control (for example,
107 \c Button.qml) must exist.
108 \li Each QML file must contain the relevant type from the \l {Qt Quick Templates 2}
109 {QtQuick.Templates} import as the root item. For example,
110 Button.qml must contain a Button template as its root item.
111
112 If we instead used the corresponding type from the \l {Qt Quick Controls}
113 {QtQuick.Controls} import as we did in the previous section, it would not work:
114 the control we were defining would try to derive from itself.
115 \li A \l {Module Definition qmldir Files}{qmldir} file must exist alongside
116 the QML file(s). Below is an example of a simple \c qmldir file for a style that
117 provides a button:
118
119 \badcode
120 module MyStyle
121 Button 2.15 Button.qml
122 \endcode
123
124 If you're using \l {Compile-Time Style Selection}{compile-time style
125 selection}, the qmldir should also import the fallback style:
126
127 \badcode
128 # ...
129 import QtQuick.Controls.Basic auto
130 \endcode
131
132 This can also be done for \l {Run-Time Style Selection}{run-time style selection}
133 instead of using, for example, \l QQuickStyle::setFallbackStyle().
134
135 The directory structure for such a style looks like this:
136
137 \badcode
138 MyStyle
139 ├─── Button.qml
140 └─── qmldir
141 \endcode
142 \li The files must be in a directory that is findable via the \l[QtQml]{QML Import Path}.
143
144 For example, if the path to \e MyStyle directory mentioned above was
145 \c /home/user/MyApp/MyStyle, then \c /home/user/MyApp must be added to
146 the QML import path.
147
148 To \l {Using Styles in Qt Quick Controls}{use} \e MyStyle in \e MyApp,
149 refer to it by name:
150
151 \list
152 \li \c {./MyApp -style MyStyle}
153 \endlist
154
155 The style name must match the casing of the style directory; passing
156 \e mystyle or \e MYSTYLE is not supported.
157 \endlist
158
159 By default, the styling system uses the Basic style as a fallback for
160 controls that aren't implemented. To customize or extend any other built-in
161 style, it is possible to specify a different fallback style using
162 \l[QtQuickControls2]{QQuickStyle}.
163
164 What this means is that you can implement as many controls as you like for
165 your custom style, and place them almost anywhere. It also allows users to
166 create their own styles for your application.
167
168 \section3 Previewing Custom Styles in Qt Quick Designer
169
170 Using the approach above, it is possible to preview a custom style
171 in Qt Quick Designer. In order to do so,
172 ensure that the project has a
173 \l {Qt Quick Controls Configuration File}{qtquickcontrols2.conf} file,
174 and that the following entry exists:
175
176 \badcode
177 [Controls]
178 Style=MyStyle
179 \endcode
180
181 For more information, take a look at the
182 \l {Qt Quick Controls - Flat Style}{Flat Style example}.
183
184 \section2 Style-specific C++ Extensions
185
186 Sometimes you may need to use C++ to extend your custom style.
187
188 \list
189 \li If the style that uses the type is the only style used by an
190 application, register the type with the QML engine by adding the QML_ELEMENT
191 macro and making the file part of your QML module:
192 \br
193 \br
194
195 \if defined(onlinedocs)
196 \tab {expose-cpp-to-qml}{tab-cmake}{CMake}{checked}
197 \tab {expose-cpp-to-qml}{tab-qmake}{qmake}{}
198 \tabcontent {tab-cmake}
199 \else
200 \section3 Using CMake
201 \endif
202 \badcode
203 qt_add_qml_module(ACoolItem
204 URI MyItems
205 VERSION 1.0
206 SOURCES
207 acoolcppitem.cpp acoolcppitem.h
208 )
209 \endcode
210 \if defined(onlinedocs)
211 \endtabcontent
212 \tabcontent {tab-qmake}
213 \else
214 \section3 Using QMake
215 \endif
216 \code
217 CONFIG += qmltypes
218 QML_IMPORT_NAME = MyItems
219 QML_IMPORT_MAJOR_VERSION = 1
220 \endcode
221
222 If the header the class is declared in is not accessible from your
223 project's include path, you may have to amend the include path so
224 that the generated registration code can be compiled.
225
226 \code
227 INCLUDEPATH += MyItems
228 \endcode
229 \if defined(onlinedocs)
230 \endtabcontent
231 \endif
232
233 See \l {Defining QML Types from C++} and \l {Building a QML application}
234 for more information.
235 \li If the style that uses the type is one of many styles used by an
236 application, consider putting each style into a separate module. The
237 modules will then be loaded on demand.
238 \endlist
239
240 \section3 Considerations for custom styles
241
242 When implementing your own style and customizing controls, there are some
243 points to keep in mind to ensure that your application is as performant as
244 possible.
245
246 \section4 Avoid assigning an id to styles' implementations of item delegates
247
248 As explained in \l {Definition of a Style}, when you implement your
249 own style for a control, you start off with the relevant template for
250 that control. For example, a style's \c Button.qml will be structured
251 similarly to this:
252
253 \qml
254 T.Button {
255 // ...
256
257 background: Rectangle {
258 // ...
259 }
260
261 contentItem: Text {
262 // ...
263 }
264
265 // ...
266 }
267 \endqml
268
269 When you use a Button in your application, the \c background and
270 \c contentItem items will be created and parented to the root \c Button
271 item:
272
273 \qml
274 // Creates the Button root item, the Rectangle background,
275 // and the Text contentItem.
276 Button {
277 text: qsTr("Confirm")
278 }
279 \endqml
280
281 Suppose you then needed to do a one-off customization of the Button (as
282 explained in \l {Customizing a Control}):
283
284 \include customize-button-background.qdocinc file
285
286 In QML, this would normally result in both the default \c background
287 implementation and the one-off, custom \c background items being created.
288 Qt Quick Controls uses a technique that avoids creating both items, and
289 instead only creates the custom \c background, greatly improving the
290 creation performance of controls.
291
292 This technique relies on the absence of an \l {The id Attribute}{id} in the
293 style's implementation of that item. If an id is assigned, the technique
294 cannot work, and both items will be created. For example, it can be
295 tempting to assign an id to the \c background or \c contentItem so that
296 other objects within the file can refer to those items:
297
298 \qml
299 T.Button {
300 // ...
301
302 background: Rectangle {
303 id: backgroundRect
304 // ...
305 }
306
307 contentItem: Text {
308 // Use backgroundRect in some way...
309 }
310
311 // ...
312 }
313 \endqml
314
315 With this code, every time a Button instance with a customized background
316 is created, both backgrounds will be created, resulting in sub-optimal
317 creation performance.
318
319 Prior to Qt 5.15, the old, unused background would be deleted to release
320 the resources associated with it. However, as the control does not own the
321 items, it should not delete them. As of Qt 5.15, old items are no longer
322 deleted, and so the \c backgroundRect item will live longer than it needs
323 to—typically until the application exits. Although the old item will be
324 hidden, visually unparented from the control, and removed from the
325 accessibility tree, it is important to keep the creation time and memory
326 usage of these unused items in mind when assigning an id in this context.
327
328 \section4 Avoid imperative assignments of custom items
329
330 The technique mentioned in the section above only works when an item is
331 \l {Prefer Declarative Bindings Over Imperative Assignments}{declaratively}
332 assigned for the first time, and so imperative assignments will result in
333 orphaned items. Always use declarative bindings to assign custom items
334 when possible.
335
336 \section4 Don't import QtQuick.Controls in QML implementations
337
338 When writing the QML for your style's implementation of a control,
339 it's important not to import \c {QtQuick.Controls}. Doing so will
340 prevent the QML from being compiled by the QML compiler.
341
342 \section4 Implement types used by other types
343
344 Suppose you were using ScrollViews in your application, and decided that
345 you want to customize their scroll bars. It is tempting to just implement a
346 custom ScrollBar.qml and have ScrollView pick up the customized ScrollBar
347 automatically. However, this will not work. You must implement both
348 ScrollBar.qml \e and ScrollView.qml.
349
350 \section3 Attached properties
351
352 It is common for a style to have certain properties or attributes that
353 apply to all controls. \l {Attached Properties and Attached Signal
354 Handlers}{Attached properties} are a great way of extending an item in QML
355 without having to modify any existing C++ belonging to that item. For
356 example, both the \l {Material Style}{Material} and \l {Universal
357 Style}{Universal} styles have an attached theme property that controls
358 whether an item and its children will be rendered in a light or dark theme.
359
360 As an example, let's add an attached property that controls elevation. Our
361 style will illustrate the elevation with a drop shadow; the higher the
362 elevation, the larger the shadow.
363
364 The first step is to \l {\QC: Create Qt Quick Applications}
365 {create a new Qt Quick Controls application} in \QC. After that, we
366 \l {\QC: Create C++ classes}{add a C++ type} that stores the elevation. Since
367 the type will be used for every control supported by our style, and because
368 we may wish to add other attached properties later on, we'll call it
369 MyStyle. Here is \c MyStyle.h:
370
371 \code
372 #ifndef MYSTYLE_H
373 #define MYSTYLE_H
374
375 #include <QObject>
376 #include <QtQml>
377
378 class MyStyle : public QObject
379 {
380 Q_OBJECT
381 Q_PROPERTY(int elevation READ elevation WRITE setElevation NOTIFY elevationChanged)
382
383 public:
384 explicit MyStyle(QObject *parent = nullptr);
385
386 static MyStyle *qmlAttachedProperties(QObject *object);
387
388 int elevation() const;
389 void setElevation(int elevation);
390
391 signals:
392 void elevationChanged();
393
394 private:
395 int m_elevation;
396 };
397
398 QML_DECLARE_TYPEINFO(MyStyle, QML_HAS_ATTACHED_PROPERTIES)
399
400 #endif // MYSTYLE_H
401 \endcode
402
403 \c MyStyle.cpp:
404
405 \code
406 #include "mystyle.h"
407
408 MyStyle::MyStyle(QObject *parent) :
409 QObject(parent),
410 m_elevation(0)
411 {
412 }
413
414 MyStyle *MyStyle::qmlAttachedProperties(QObject *object)
415 {
416 return new MyStyle(object);
417 }
418
419 int MyStyle::elevation() const
420 {
421 return m_elevation;
422 }
423
424 void MyStyle::setElevation(int elevation)
425 {
426 if (elevation == m_elevation)
427 return;
428
429 m_elevation = elevation;
430 emit elevationChanged();
431 }
432 \endcode
433
434 The \c MyStyle type is special in the sense that it shouldn't be
435 instantiated, but rather used for its attached properties. For that reason,
436 we register it in the following manner in \c main.cpp:
437
438 \code
439 #include <QGuiApplication>
440 #include <QQmlApplicationEngine>
441
442 #include "mystyle.h"
443
444 int main(int argc, char *argv[])
445 {
446 QGuiApplication app(argc, argv);
447
448 qmlRegisterUncreatableType<MyStyle>("MyStyle", 1, 0, "MyStyle", "MyStyle is an attached property");
449
450 QQmlApplicationEngine engine;
451 // Make the directory containing our style known to the QML engine.
452 engine.addImportPath(":/");
453 engine.load(QUrl(QLatin1String("qrc:/main.qml")));
454
455 return app.exec();
456 }
457 \endcode
458
459 We then copy \c Button.qml from the Basic style in
460 \c {$QTDIR/qml/QtQuick/Controls/Basic/} into a new \c myproject folder in our
461 project directory. Add the newly copied \c Button.qml to \c qml.qrc, which is
462 the resource file that contains our QML files.
463
464 Next, we add a drop shadow to the \l {Control::}{background} delegate of
465 the Button:
466
467 \qml
468 // ...
469 import QtQuick.Effects
470 import MyStyle
471 // ...
472
473 background: Rectangle {
474 // ...
475
476 layer.enabled: control.enabled && control.MyStyle.elevation > 0
477 layer.effect: MultiEffect {
478 shadowEnabled: true
479 shadowHorizontalOffset: 3
480 shadowVerticalOffset: 3
481 shadowColor: control.visualFocus ? "#330066ff" : "#aaaaaa"
482 shadowBlur: control.pressed ? 0.8 : 0.4
483 }
484 }
485 \endqml
486
487 Note that we:
488
489 \list
490 \li Don't bother using the drop shadow when the elevation is \c 0
491 \li Change the shadow's color depending on whether or not the button has
492 focus
493 \li Make the size of the shadow depend on the elevation
494 \endlist
495
496 To try out the attached property, we create a \l Row with two Buttons in
497 \c main.qml:
498
499 \qml
500 import QtQuick
501 import QtQuick.Controls
502
503 import MyStyle 1.0
504
505 ApplicationWindow {
506 id: window
507 width: 400
508 height: 400
509 visible: true
510
511 Row {
512 spacing: 20
513 anchors.centerIn: parent
514
515 Button {
516 text: "Button 1"
517 }
518 Button {
519 text: "Button 2"
520 MyStyle.elevation: 10
521 }
522 }
523 }
524 \endqml
525
526 One button has no elevation, and the other has an elevation of \c 10.
527
528 With that in place, we can run our example. To tell the application to
529 use our new style, we pass \c {-style MyStyle} as an application
530 argument, but there are \l {Using Styles in Qt Quick Controls}{many
531 ways} to specify the style to use.
532
533 The end result:
534
535 \image qtquickcontrols-customize-buttons.png
536 {Custom styled buttons}
537
538 Note that the \c {import MyStyle 1.0} statement is only necessary
539 because we are using the attached property belonging to \c MyStyle.
540 Both buttons will use our custom style, even if we were to remove the
541 import.
542
543 \section1 Customization Reference
544
545 The following snippets present examples where the Basic style's controls
546 have been customized using the same approach as the
547 \l {Customizing a Control} section. The code can be used as a starting
548 point to implement a custom look and feel.
549
550 \note The \l {macOS Style}{macOS} and \l {Windows Style}{Windows} styles
551 are not suitable for customizing.
552 \include customizing-native-styles.qdocinc
553
554 \note When modifying the size of controls, the actual content size will
555 typically remain the same. For example, some styles may make their Button
556 fill the bounds of the control, but horizontally and/or vertically center
557 the check indicator and text of a CheckBox. If the default resizing
558 behaviour is not desired, override the respective delegate(s).
559
560 \section2 Customizing ApplicationWindow
561
562 ApplicationWindow consists of one visual item:
563 \l {ApplicationWindow::background}{background}.
564
565 \qml
566 import QtQuick
567 import QtQuick.Controls.Basic
568
569 ApplicationWindow {
570 visible: true
571
572 background: Rectangle {
573 gradient: Gradient {
574 GradientStop { position: 0; color: "#ffffff" }
575 GradientStop { position: 1; color: "#c1bbf9" }
576 }
577 }
578 }
579 \endqml
580
581
582 \section2 Customizing BusyIndicator
583
584 BusyIndicator consists of two visual items: \l {Control::background}{background}
585 and \l {Control::}{contentItem}.
586
587 \image qtquickcontrols-busyindicator-custom.png
588 {Custom styled busy indicator}
589
590 \snippet qtquickcontrols-busyindicator-custom.qml file
591
592
593 \section2 Customizing Button
594
595 Button consists of two visual items: \l {Control::background}{background}
596 and \l {Control::}{contentItem}.
597
598 \image qtquickcontrols-button-custom.png
599 {Custom styled button}
600
601 \snippet qtquickcontrols-button-custom.qml file
602
603
604 \section2 Customizing CheckBox
605
606 CheckBox consists of three visual items: \l {Control::background}{background},
607 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
608
609 \image qtquickcontrols-checkbox-custom.png
610 {Custom styled checkbox}
611
612 \snippet qtquickcontrols-checkbox-custom.qml file
613
614 \section2 Customizing CheckDelegate
615
616 CheckDelegate consists of three visual items: \l {Control::background}{background},
617 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
618
619 \image qtquickcontrols-checkdelegate-custom.png
620 {Custom styled check delegate}
621
622 \snippet qtquickcontrols-checkdelegate-custom.qml file
623
624
625 \section2 Customizing ComboBox
626
627 ComboBox consists of \l {Control::background}{background},
628 \l {Control::}{contentItem}, \l {ComboBox::popup}{popup},
629 \l {ComboBox::indicator}{indicator}, and \l {ComboBox::delegate}{delegate}.
630
631 \image qtquickcontrols-combobox-custom.png
632 {Custom styled combo box}
633
634 \snippet qtquickcontrols-combobox-custom.qml file
635
636 As explained in \l {ComboBox Model Roles}, ComboBox supports multiple
637 types of models.
638
639 Since \l {qml-data-models}{all the models provide an anonymous property}
640 with \c modelData, the following expression retrieves the right text in
641 all cases:
642
643 \code
644 text: model[control.textRole]
645 \endcode
646
647 When you provide a specific \c textRole and a model with structured
648 data that provides the selected role, this is expression is a regular
649 property lookup. When you provide a model with singular data, such as
650 a list of strings, and an empty \c textRole, this expression retrieves
651 the \c modelData.
652
653 \section2 Customizing DelayButton
654
655 DelayButton consists of two visual items: \l {Control::background}{background}
656 and \l {Control::}{contentItem}.
657
658 \image qtquickcontrols-delaybutton-custom.png
659 {Custom styled delay button}
660
661 \snippet qtquickcontrols-delaybutton-custom.qml file
662
663
664 \section2 Customizing Dial
665
666 Dial consists of two visual items: \l {Control::background}{background}
667 and \l {Dial::handle}{handle}.
668
669 \image qtquickcontrols-dial-custom.png
670 {Custom styled dial}
671
672 \snippet qtquickcontrols-dial-custom.qml file
673
674
675 \section2 Customizing DoubleSpinBox
676
677 DoubleSpinBox can be customized in the same manner as
678 \l {Customizing SpinBox}{Button}.
679
680
681 \section2 Customizing Drawer
682
683 Drawer can have a visual \l {Control::background}{background}
684 item.
685
686 \code
687 background: Rectangle {
688 Rectangle {
689 x: parent.width - 1
690 width: 1
691 height: parent.height
692 color: "#21be2b"
693 }
694 }
695 \endcode
696
697
698 \section2 Customizing Frame
699
700 Frame consists of one visual item: \l {Control::background}{background}.
701
702 \image qtquickcontrols-frame-custom.png
703 {Custom styled frame}
704
705 \snippet qtquickcontrols-frame-custom.qml file
706
707
708 \section2 Customizing GroupBox
709
710 GroupBox consists of two visual items: \l {Control::background}{background}
711 and \l {GroupBox::label}{label}.
712
713 \image qtquickcontrols-groupbox-custom.png
714 {Custom styled group box}
715
716 \snippet qtquickcontrols-groupbox-custom.qml file
717
718
719 \section2 Customizing ItemDelegate
720
721 ItemDelegate consists of two visual items: \l {Control::background}{background}
722 and \l {Control::}{contentItem}.
723
724 \image qtquickcontrols-itemdelegate-custom.png
725 {Custom styled item delegate}
726
727 \snippet qtquickcontrols-itemdelegate-custom.qml file
728
729
730 \section2 Customizing Label
731
732 Label can have a visual \l {Label::background}{background} item.
733
734 \image qtquickcontrols-label-custom.png
735 {Custom styled label}
736
737 \snippet qtquickcontrols-label-custom.qml file
738
739
740 \section2 Customizing Menu
741
742 \list
743 \li \l Menu consists of a visual \l {Popup::background}{background} item.
744 \li \l MenuItem consists of four visual items: \l {Control::background}{background},
745 \l {Control::}{contentItem}, \l {AbstractButton::}{indicator}, and
746 \l {MenuItem::}{arrow}.
747 \li \l MenuSeparator consists of a visual \l {Control::background}{background} and
748 \l {Control::}{contentItem}.
749 \endlist
750
751 \image qtquickcontrols-menu-custom.png
752 {Custom styled menu}
753
754 \quotefromfile qtquickcontrols-menu-custom.qml
755 \skipto import QtQuick
756 \printuntil import QtQuick.Controls.Basic
757 \skipto Menu
758 \printto eof
759
760
761 \section2 Customizing MenuBar
762
763 MenuBar can have a visual \l {Control::background}{background} item,
764 and MenuBarItem consists of two visual items: \l {Control::background}
765 {background} and \l {Control::}{contentItem}.
766
767 \image qtquickcontrols-menubar-custom.png
768 {Custom styled menu bar with File and Edit menus}
769
770 \quotefromfile qtquickcontrols-menubar-custom.qml
771 \skipto import QtQuick
772 \printuntil import QtQuick.Controls.Basic
773 \skipto MenuBar
774 \printto eof
775
776
777 \section2 Customizing PageIndicator
778
779 PageIndicator consists of a \l {Control::background}{background}, \l {Control::}{contentItem}, and \l {PageIndicator::delegate}{delegate}.
780
781 \image qtquickcontrols-pageindicator-custom.png
782 {Custom styled page indicator showing multiple pages}
783
784 \snippet qtquickcontrols-pageindicator-custom.qml file
785
786
787 \section2 Customizing Pane
788
789 Pane consists of a \l {Control::background}{background}.
790
791 \image qtquickcontrols-pane-custom.png
792 {Custom styled pane with decorative background}
793
794 \snippet qtquickcontrols-pane-custom.qml file
795
796
797 \section2 Customizing Popup
798
799 Popup consists of a \l {Popup::background}{background} and
800 \l {Popup::contentItem}{contentItem}.
801
802 \image qtquickcontrols-popup-custom.png
803 {Custom styled popup with border and shadow}
804
805 \quotefromfile qtquickcontrols-popup-custom.qml
806 \skipto import QtQuick
807 \printuntil import QtQuick.Controls.Basic
808 \codeline
809 \skipto Popup
810 \printuntil {
811 \printuntil }
812 \printuntil }
813 \printuntil }
814
815
816 \section2 Customizing ProgressBar
817
818 ProgressBar consists of two visual items: \l {Control::background}{background}
819 and \l {Control::}{contentItem}.
820
821 \image qtquickcontrols-progressbar-custom.png
822 {Custom styled progress bar showing partial completion}
823
824 \snippet qtquickcontrols-progressbar-custom.qml file
825
826 Above, the contentItem is also animated to represent an
827 \l {ProgressBar::}{indeterminate} progress bar state.
828
829
830 \section2 Customizing RadioButton
831
832 RadioButton consists of three visual items: \l {Control::background}{background},
833 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
834
835 \image qtquickcontrols-radiobutton-custom.png
836 {Custom styled radio button in selected state}
837
838 \snippet qtquickcontrols-radiobutton-custom.qml file
839
840
841 \section2 Customizing RadioDelegate
842
843 RadioDelegate consists of three visual items: \l {Control::background}{background},
844 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
845
846 \image qtquickcontrols-radiodelegate-custom.png
847 {Custom styled radio delegate in list}
848
849 \snippet qtquickcontrols-radiodelegate-custom.qml file
850
851
852 \section2 Customizing RangeSlider
853
854 RangeSlider consists of three visual items:
855 \l {Control::background}{background},
856 \l {RangeSlider::first}{first.handle} and
857 \l {RangeSlider::second.handle}{second.handle}.
858
859 \image qtquickcontrols-rangeslider-custom.png
860 {Custom styled range slider}
861
862 \snippet qtquickcontrols-rangeslider-custom.qml file
863
864
865 \section2 Customizing RoundButton
866
867 RoundButton can be customized in the same manner as
868 \l {Customizing Button}{Button}.
869
870
871 \section2 Customizing ScrollBar
872
873 ScrollBar consists of two visual items: \l {Control::background}{background}
874 and \l {Control::}{contentItem}.
875
876 \image qtquickcontrols-scrollbar-custom.png
877 {Custom styled scroll bar}
878
879 \snippet qtquickcontrols-scrollbar-custom.qml file
880
881
882 \section2 Customizing ScrollIndicator
883
884 ScrollIndicator consists of two visual items: \l {Control::background}{background}
885 and \l {Control::}{contentItem}.
886
887 \image qtquickcontrols-scrollindicator-custom.png
888 {Custom styled scroll indicator}
889
890 \snippet qtquickcontrols-scrollindicator-custom.qml file
891
892
893 \section2 Customizing ScrollView
894
895 ScrollView consists of a \l {Control::background}{background} item,
896 and horizontal and vertical scroll bars.
897
898 \image qtquickcontrols-scrollview-custom.png
899 {Custom styled scroll view}
900
901 \snippet qtquickcontrols-scrollview-custom.qml file
902
903
904 \section2 Customizing Slider
905
906 Slider consists of two visual items: \l {Control::background}{background},
907 and \l {Slider::handle}{handle}.
908
909 \image qtquickcontrols-slider-custom.png
910 {Custom styled slider}
911
912 \snippet qtquickcontrols-slider-custom.qml file
913
914
915 \section2 Customizing SpinBox
916
917 SpinBox consists of four visual items: \l {Control::background}{background},
918 \l {Control::}{contentItem}, \l {SpinBox::up.indicator}{up indicator},
919 and \l {SpinBox::down.indicator}{down indicator}.
920
921 \image qtquickcontrols-spinbox-custom.png
922 {Custom styled spin box}
923
924 \snippet qtquickcontrols-spinbox-custom.qml file
925
926
927 \section2 Customizing SplitView
928
929 SplitView consists of a visual \l {SplitView::handle}{handle} delegate.
930
931 \image qtquickcontrols-splitview-custom.png
932 {Custom styled split view}
933
934 \snippet qtquickcontrols-splitview-custom.qml 1
935
936
937 \section2 Customizing StackView
938
939 StackView can have a visual \l {Control::background}{background}
940 item, and it allows customizing the transitions that are used for
941 push, pop, and replace operations.
942
943 \snippet qtquickcontrols-stackview-custom.qml file
944
945
946 \section2 Customizing SwipeDelegate
947
948 SwipeDelegate consists of six visual items: \l {Control::background}{background},
949 \l {Control::}{contentItem}, \l {AbstractButton::indicator}{indicator},
950 \c swipe.left, \c swipe.right, and \c swipe.behind.
951
952 \image qtquickcontrols-swipedelegate-custom.png
953 {Custom styled swipe delegate}
954
955 \snippet qtquickcontrols-swipedelegate-custom.qml file
956
957
958 \section2 Customizing SwipeView
959
960 SwipeView can have a visual \l {Control::background}{background}
961 item. The navigation is implemented by the \l {Control::}{contentItem}.
962
963 \snippet qtquickcontrols-swipeview-custom.qml file
964
965
966 \section2 Customizing Switch
967
968 Switch consists of three visual items: \l {Control::background}{background},
969 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
970
971 \image qtquickcontrols-switch-custom.png
972 {Custom styled switch}
973
974 \snippet qtquickcontrols-switch-custom.qml file
975
976 \section2 Customizing SwitchDelegate
977
978 SwitchDelegate consists of three visual items: \l {Control::background}{background},
979 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
980
981 \image qtquickcontrols-switchdelegate-custom.png
982 {Custom styled switch delegate}
983
984 \snippet qtquickcontrols-switchdelegate-custom.qml file
985
986
987 \section2 Customizing TabBar
988
989 TabBar consists of two visual items: \l {Control::background}{background},
990 and \l {Control::}{contentItem}.
991
992 \image qtquickcontrols-tabbar-custom.png
993 {Custom styled tab bar}
994
995 \snippet qtquickcontrols-tabbar-custom.qml file
996
997
998 \section2 Customizing TabButton
999
1000 TabButton can be customized in the same manner as
1001 \l {Customizing Button}{Button}.
1002
1003
1004 \section2 Customizing TextArea
1005
1006 TextArea consists of a \l {TextArea::background}{background} item.
1007
1008 \image qtquickcontrols-textarea-custom.png
1009 {Custom styled text area}
1010
1011 \snippet qtquickcontrols-textarea-custom.qml file
1012
1013
1014 \section2 Customizing TextField
1015
1016 TextField consists of a \l {TextField::background}{background} item.
1017
1018 \image qtquickcontrols-textfield-custom.png
1019 {Custom styled text field}
1020
1021 \snippet qtquickcontrols-textfield-custom.qml file
1022
1023
1024 \section2 Customizing ToolBar
1025
1026 ToolBar consists of one visual item: \l {Control::background}{background}.
1027
1028 \image qtquickcontrols-toolbar-custom.png
1029 {Custom styled tool bar}
1030
1031 \snippet qtquickcontrols-toolbar-custom.qml file
1032
1033
1034 \section2 Customizing ToolButton
1035
1036 ToolButton consists of two visual items: \l {Control::background}{background}
1037 and \l {Control::}{contentItem}.
1038
1039 \image qtquickcontrols-toolbutton-custom.png
1040 {Custom styled tool button}
1041
1042 \snippet qtquickcontrols-toolbutton-custom.qml file
1043
1044
1045 \section2 Customizing ToolSeparator
1046
1047 ToolSeparator consists of two visual items: \l {Control::background}{background}
1048 and \l {Control::}{contentItem}.
1049
1050 \image qtquickcontrols-toolseparator-custom.png
1051 {Custom styled tool separator}
1052
1053 \snippet qtquickcontrols-toolseparator-custom.qml file
1054
1055
1056 \section2 Customizing ToolTip
1057
1058 ToolTip consists of two visual items: \l {Popup::background}{background}
1059 and \l {Popup::}{contentItem}.
1060
1061 \quotefromfile qtquickcontrols-tooltip-custom.qml
1062 \skipto import QtQuick
1063 \printuntil import QtQuick.Controls.Basic
1064 \skipto ToolTip
1065 \printuntil }
1066 \printuntil }
1067 \printuntil }
1068
1069 \include qquicktooltip.qdocinc customize-note
1070
1071 \section2 Customizing Tumbler
1072
1073 Tumbler consists of three visual items:
1074 \l {Control::background}{background},
1075 \l {Control::}{contentItem}, and
1076 \l {Tumbler::delegate}{delegate}.
1077
1078 \image qtquickcontrols-tumbler-custom.png
1079 {Custom styled tumbler}
1080
1081 \snippet qtquickcontrols-tumbler-custom.qml file
1082
1083 If you want to define your own contentItem, use either a \l ListView or
1084 \l PathView as the root item. For a wrapping Tumbler, use PathView:
1085
1086 \snippet qtquickcontrols-tumbler-pathView.qml contentItem
1087
1088 For a non-wrapping Tumbler, use ListView:
1089
1090 \snippet qtquickcontrols-tumbler-listView.qml contentItem
1091
1092 \section2 Customizing TableViewDelegate
1093
1094 TableViewDelegate inherits \l ItemDelegate, which means that it's composed of two
1095 visual items:
1096 \l [QML]{Control::}{background} and
1097 \l [QML]{Control::}{contentItem}.
1098
1099 You can always assign your own custom edit delegate to
1100 \l [QML]{TableView::}{editDelegate} if you have needs
1101 outside what the default edit delegate offers.
1102
1103 \image qtquickcontrols-tableviewdelegate-custom.png
1104 {Custom styled table view delegate}
1105
1106 \snippet qtquickcontrols-tableviewdelegate-custom.qml delegate
1107
1108 \section2 Customizing HeaderViewDelegate
1109
1110 HeaderViewDelegate inherits \l TableViewDelegate, which means that it's
1111 composed of two items:
1112 \l [QML]{Control::}{background} and
1113 \l [QML]{Control::}{contentItem}.
1114 You can always customize them with any arbitrary items.
1115
1116 \image qtquickcontrols-headerviewdelegate-custom.png
1117 {Custom styled header view delegate}
1118
1119 Here is an example of customizing the horizontal header view delegate:
1120
1121 \snippet qtquickcontrols-headerviewdelegate-custom.qml horizontal-delegate
1122
1123 Here is an example of customizing the vertical header view delegate:
1124
1125 \snippet qtquickcontrols-headerviewdelegate-custom.qml vertical-delegate
1126
1127 \section1 Styling Controls using StyleKit
1128
1129 The \l{Qt Labs StyleKit} module provides a set of QML types for styling
1130 Qt Quick Controls, built on top of \l{Qt Quick Templates}.
1131 It lets you define a complete visual style for
1132 all your controls from a single Style object, including support for
1133 themes, state-based styling, and transitions. StyleKit handles the
1134 underlying template implementation automatically, letting you focus
1135 purely on visual aspects such as colors, dimensions, borders, and shadows.
1136
1137 The \l{Qt Labs StyleKit} module is a Technology Preview module in
1138 Qt 6.11.
1139
1140*/