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 create a new Qt Quick Controls application
365 \l {\QC: Create Qt Quick Applications}{in \QC} or
366 \l {\QVSC: Tutorial: Qt Quick application}{in \QVSC}. After that, we add a
367 C++ type (\l {\QC: Create C++ classes}{in \QC} or
368 \l{\QVSC: Add files to projects}{in \QVSC}) that stores the elevation.
369 Since the type will be used for every control supported by our style, and
370 because we may wish to add other attached properties later on, we'll call it
371 MyStyle. Here is \c MyStyle.h:
372
373 \code
374 #ifndef MYSTYLE_H
375 #define MYSTYLE_H
376
377 #include <QObject>
378 #include <QtQml>
379
380 class MyStyle : public QObject
381 {
382 Q_OBJECT
383 Q_PROPERTY(int elevation READ elevation WRITE setElevation NOTIFY elevationChanged)
384
385 public:
386 explicit MyStyle(QObject *parent = nullptr);
387
388 static MyStyle *qmlAttachedProperties(QObject *object);
389
390 int elevation() const;
391 void setElevation(int elevation);
392
393 signals:
394 void elevationChanged();
395
396 private:
397 int m_elevation;
398 };
399
400 QML_DECLARE_TYPEINFO(MyStyle, QML_HAS_ATTACHED_PROPERTIES)
401
402 #endif // MYSTYLE_H
403 \endcode
404
405 \c MyStyle.cpp:
406
407 \code
408 #include "mystyle.h"
409
410 MyStyle::MyStyle(QObject *parent) :
411 QObject(parent),
412 m_elevation(0)
413 {
414 }
415
416 MyStyle *MyStyle::qmlAttachedProperties(QObject *object)
417 {
418 return new MyStyle(object);
419 }
420
421 int MyStyle::elevation() const
422 {
423 return m_elevation;
424 }
425
426 void MyStyle::setElevation(int elevation)
427 {
428 if (elevation == m_elevation)
429 return;
430
431 m_elevation = elevation;
432 emit elevationChanged();
433 }
434 \endcode
435
436 The \c MyStyle type is special in the sense that it shouldn't be
437 instantiated, but rather used for its attached properties. For that reason,
438 we register it in the following manner in \c main.cpp:
439
440 \code
441 #include <QGuiApplication>
442 #include <QQmlApplicationEngine>
443
444 #include "mystyle.h"
445
446 int main(int argc, char *argv[])
447 {
448 QGuiApplication app(argc, argv);
449
450 qmlRegisterUncreatableType<MyStyle>("MyStyle", 1, 0, "MyStyle", "MyStyle is an attached property");
451
452 QQmlApplicationEngine engine;
453 // Make the directory containing our style known to the QML engine.
454 engine.addImportPath(":/");
455 engine.load(QUrl(QLatin1String("qrc:/main.qml")));
456
457 return app.exec();
458 }
459 \endcode
460
461 We then copy \c Button.qml from the Basic style in
462 \c {$QTDIR/qml/QtQuick/Controls/Basic/} into a new \c myproject folder in our
463 project directory. Add the newly copied \c Button.qml to \c qml.qrc, which is
464 the resource file that contains our QML files.
465
466 Next, we add a drop shadow to the \l {Control::}{background} delegate of
467 the Button:
468
469 \qml
470 // ...
471 import QtQuick.Effects
472 import MyStyle
473 // ...
474
475 background: Rectangle {
476 // ...
477
478 layer.enabled: control.enabled && control.MyStyle.elevation > 0
479 layer.effect: MultiEffect {
480 shadowEnabled: true
481 shadowHorizontalOffset: 3
482 shadowVerticalOffset: 3
483 shadowColor: control.visualFocus ? "#330066ff" : "#aaaaaa"
484 shadowBlur: control.pressed ? 0.8 : 0.4
485 }
486 }
487 \endqml
488
489 Note that we:
490
491 \list
492 \li Don't bother using the drop shadow when the elevation is \c 0
493 \li Change the shadow's color depending on whether or not the button has
494 focus
495 \li Make the size of the shadow depend on the elevation
496 \endlist
497
498 To try out the attached property, we create a \l Row with two Buttons in
499 \c main.qml:
500
501 \qml
502 import QtQuick
503 import QtQuick.Controls
504
505 import MyStyle 1.0
506
507 ApplicationWindow {
508 id: window
509 width: 400
510 height: 400
511 visible: true
512
513 Row {
514 spacing: 20
515 anchors.centerIn: parent
516
517 Button {
518 text: "Button 1"
519 }
520 Button {
521 text: "Button 2"
522 MyStyle.elevation: 10
523 }
524 }
525 }
526 \endqml
527
528 One button has no elevation, and the other has an elevation of \c 10.
529
530 With that in place, we can run our example. To tell the application to
531 use our new style, we pass \c {-style MyStyle} as an application
532 argument, but there are \l {Using Styles in Qt Quick Controls}{many
533 ways} to specify the style to use.
534
535 The end result:
536
537 \image qtquickcontrols-customize-buttons.png
538 {Custom styled buttons}
539
540 Note that the \c {import MyStyle 1.0} statement is only necessary
541 because we are using the attached property belonging to \c MyStyle.
542 Both buttons will use our custom style, even if we were to remove the
543 import.
544
545 \section1 Customization Reference
546
547 The following snippets present examples where the Basic style's controls
548 have been customized using the same approach as the
549 \l {Customizing a Control} section. The code can be used as a starting
550 point to implement a custom look and feel.
551
552 \note The \l {macOS Style}{macOS} and \l {Windows Style}{Windows} styles
553 are not suitable for customizing.
554 \include customizing-native-styles.qdocinc
555
556 \note When modifying the size of controls, the actual content size will
557 typically remain the same. For example, some styles may make their Button
558 fill the bounds of the control, but horizontally and/or vertically center
559 the check indicator and text of a CheckBox. If the default resizing
560 behaviour is not desired, override the respective delegate(s).
561
562 \section2 Customizing ApplicationWindow
563
564 ApplicationWindow consists of one visual item:
565 \l {ApplicationWindow::background}{background}.
566
567 \qml
568 import QtQuick
569 import QtQuick.Controls.Basic
570
571 ApplicationWindow {
572 visible: true
573
574 background: Rectangle {
575 gradient: Gradient {
576 GradientStop { position: 0; color: "#ffffff" }
577 GradientStop { position: 1; color: "#c1bbf9" }
578 }
579 }
580 }
581 \endqml
582
583
584 \section2 Customizing BusyIndicator
585
586 BusyIndicator consists of two visual items: \l {Control::background}{background}
587 and \l {Control::}{contentItem}.
588
589 \image qtquickcontrols-busyindicator-custom.png
590 {Custom styled busy indicator}
591
592 \snippet qtquickcontrols-busyindicator-custom.qml file
593
594
595 \section2 Customizing Button
596
597 Button consists of two visual items: \l {Control::background}{background}
598 and \l {Control::}{contentItem}.
599
600 \image qtquickcontrols-button-custom.png
601 {Custom styled button}
602
603 \snippet qtquickcontrols-button-custom.qml file
604
605
606 \section2 Customizing CheckBox
607
608 CheckBox consists of three visual items: \l {Control::background}{background},
609 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
610
611 \image qtquickcontrols-checkbox-custom.png
612 {Custom styled checkbox}
613
614 \snippet qtquickcontrols-checkbox-custom.qml file
615
616 \section2 Customizing CheckDelegate
617
618 CheckDelegate consists of three visual items: \l {Control::background}{background},
619 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
620
621 \image qtquickcontrols-checkdelegate-custom.png
622 {Custom styled check delegate}
623
624 \snippet qtquickcontrols-checkdelegate-custom.qml file
625
626
627 \section2 Customizing ComboBox
628
629 ComboBox consists of \l {Control::background}{background},
630 \l {Control::}{contentItem}, \l {ComboBox::popup}{popup},
631 \l {ComboBox::indicator}{indicator}, and \l {ComboBox::delegate}{delegate}.
632
633 \image qtquickcontrols-combobox-custom.png
634 {Custom styled combo box}
635
636 \snippet qtquickcontrols-combobox-custom.qml file
637
638 As explained in \l {ComboBox Model Roles}, ComboBox supports multiple
639 types of models.
640
641 Since \l {qml-data-models}{all the models provide an anonymous property}
642 with \c modelData, the following expression retrieves the right text in
643 all cases:
644
645 \code
646 text: model[control.textRole]
647 \endcode
648
649 When you provide a specific \c textRole and a model with structured
650 data that provides the selected role, this is expression is a regular
651 property lookup. When you provide a model with singular data, such as
652 a list of strings, and an empty \c textRole, this expression retrieves
653 the \c modelData.
654
655 \section2 Customizing DelayButton
656
657 DelayButton consists of two visual items: \l {Control::background}{background}
658 and \l {Control::}{contentItem}.
659
660 \image qtquickcontrols-delaybutton-custom.png
661 {Custom styled delay button}
662
663 \snippet qtquickcontrols-delaybutton-custom.qml file
664
665
666 \section2 Customizing Dial
667
668 Dial consists of two visual items: \l {Control::background}{background}
669 and \l {Dial::handle}{handle}.
670
671 \image qtquickcontrols-dial-custom.png
672 {Custom styled dial}
673
674 \snippet qtquickcontrols-dial-custom.qml file
675
676
677 \section2 Customizing DoubleSpinBox
678
679 DoubleSpinBox can be customized in the same manner as
680 \l {Customizing SpinBox}{Button}.
681
682
683 \section2 Customizing Drawer
684
685 Drawer can have a visual \l {Control::background}{background}
686 item.
687
688 \code
689 background: Rectangle {
690 Rectangle {
691 x: parent.width - 1
692 width: 1
693 height: parent.height
694 color: "#21be2b"
695 }
696 }
697 \endcode
698
699
700 \section2 Customizing Frame
701
702 Frame consists of one visual item: \l {Control::background}{background}.
703
704 \image qtquickcontrols-frame-custom.png
705 {Custom styled frame}
706
707 \snippet qtquickcontrols-frame-custom.qml file
708
709
710 \section2 Customizing GroupBox
711
712 GroupBox consists of two visual items: \l {Control::background}{background}
713 and \l {GroupBox::label}{label}.
714
715 \image qtquickcontrols-groupbox-custom.png
716 {Custom styled group box}
717
718 \snippet qtquickcontrols-groupbox-custom.qml file
719
720
721 \section2 Customizing ItemDelegate
722
723 ItemDelegate consists of two visual items: \l {Control::background}{background}
724 and \l {Control::}{contentItem}.
725
726 \image qtquickcontrols-itemdelegate-custom.png
727 {Custom styled item delegate}
728
729 \snippet qtquickcontrols-itemdelegate-custom.qml file
730
731
732 \section2 Customizing Label
733
734 Label can have a visual \l {Label::background}{background} item.
735
736 \image qtquickcontrols-label-custom.png
737 {Custom styled label}
738
739 \snippet qtquickcontrols-label-custom.qml file
740
741
742 \section2 Customizing Menu
743
744 \list
745 \li \l Menu consists of a visual \l {Popup::background}{background} item.
746 \li \l MenuItem consists of four visual items: \l {Control::background}{background},
747 \l {Control::}{contentItem}, \l {AbstractButton::}{indicator}, and
748 \l {MenuItem::}{arrow}.
749 \li \l MenuSeparator consists of a visual \l {Control::background}{background} and
750 \l {Control::}{contentItem}.
751 \endlist
752
753 \image qtquickcontrols-menu-custom.png
754 {Custom styled menu}
755
756 \quotefromfile qtquickcontrols-menu-custom.qml
757 \skipto import QtQuick
758 \printuntil import QtQuick.Controls.Basic
759 \skipto Menu
760 \printto eof
761
762
763 \section2 Customizing MenuBar
764
765 MenuBar can have a visual \l {Control::background}{background} item,
766 and MenuBarItem consists of two visual items: \l {Control::background}
767 {background} and \l {Control::}{contentItem}.
768
769 \image qtquickcontrols-menubar-custom.png
770 {Custom styled menu bar with File and Edit menus}
771
772 \quotefromfile qtquickcontrols-menubar-custom.qml
773 \skipto import QtQuick
774 \printuntil import QtQuick.Controls.Basic
775 \skipto MenuBar
776 \printto eof
777
778
779 \section2 Customizing PageIndicator
780
781 PageIndicator consists of a \l {Control::background}{background}, \l {Control::}{contentItem}, and \l {PageIndicator::delegate}{delegate}.
782
783 \image qtquickcontrols-pageindicator-custom.png
784 {Custom styled page indicator showing multiple pages}
785
786 \snippet qtquickcontrols-pageindicator-custom.qml file
787
788
789 \section2 Customizing Pane
790
791 Pane consists of a \l {Control::background}{background}.
792
793 \image qtquickcontrols-pane-custom.png
794 {Custom styled pane with decorative background}
795
796 \snippet qtquickcontrols-pane-custom.qml file
797
798
799 \section2 Customizing Popup
800
801 Popup consists of a \l {Popup::background}{background} and
802 \l {Popup::contentItem}{contentItem}.
803
804 \image qtquickcontrols-popup-custom.png
805 {Custom styled popup with border and shadow}
806
807 \quotefromfile qtquickcontrols-popup-custom.qml
808 \skipto import QtQuick
809 \printuntil import QtQuick.Controls.Basic
810 \codeline
811 \skipto Popup
812 \printuntil {
813 \printuntil }
814 \printuntil }
815 \printuntil }
816
817
818 \section2 Customizing ProgressBar
819
820 ProgressBar consists of two visual items: \l {Control::background}{background}
821 and \l {Control::}{contentItem}.
822
823 \image qtquickcontrols-progressbar-custom.png
824 {Custom styled progress bar showing partial completion}
825
826 \snippet qtquickcontrols-progressbar-custom.qml file
827
828 Above, the contentItem is also animated to represent an
829 \l {ProgressBar::}{indeterminate} progress bar state.
830
831
832 \section2 Customizing RadioButton
833
834 RadioButton consists of three visual items: \l {Control::background}{background},
835 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
836
837 \image qtquickcontrols-radiobutton-custom.png
838 {Custom styled radio button in selected state}
839
840 \snippet qtquickcontrols-radiobutton-custom.qml file
841
842
843 \section2 Customizing RadioDelegate
844
845 RadioDelegate consists of three visual items: \l {Control::background}{background},
846 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
847
848 \image qtquickcontrols-radiodelegate-custom.png
849 {Custom styled radio delegate in list}
850
851 \snippet qtquickcontrols-radiodelegate-custom.qml file
852
853
854 \section2 Customizing RangeSlider
855
856 RangeSlider consists of three visual items:
857 \l {Control::background}{background},
858 \l {RangeSlider::first}{first.handle} and
859 \l {RangeSlider::second.handle}{second.handle}.
860
861 \image qtquickcontrols-rangeslider-custom.png
862 {Custom styled range slider}
863
864 \snippet qtquickcontrols-rangeslider-custom.qml file
865
866
867 \section2 Customizing RoundButton
868
869 RoundButton can be customized in the same manner as
870 \l {Customizing Button}{Button}.
871
872
873 \section2 Customizing ScrollBar
874
875 ScrollBar consists of two visual items: \l {Control::background}{background}
876 and \l {Control::}{contentItem}.
877
878 \image qtquickcontrols-scrollbar-custom.png
879 {Custom styled scroll bar}
880
881 \snippet qtquickcontrols-scrollbar-custom.qml file
882
883
884 \section2 Customizing ScrollIndicator
885
886 ScrollIndicator consists of two visual items: \l {Control::background}{background}
887 and \l {Control::}{contentItem}.
888
889 \image qtquickcontrols-scrollindicator-custom.png
890 {Custom styled scroll indicator}
891
892 \snippet qtquickcontrols-scrollindicator-custom.qml file
893
894
895 \section2 Customizing ScrollView
896
897 ScrollView consists of a \l {Control::background}{background} item,
898 and horizontal and vertical scroll bars.
899
900 \image qtquickcontrols-scrollview-custom.png
901 {Custom styled scroll view}
902
903 \snippet qtquickcontrols-scrollview-custom.qml file
904
905
906 \section2 Customizing Slider
907
908 Slider consists of two visual items: \l {Control::background}{background},
909 and \l {Slider::handle}{handle}.
910
911 \image qtquickcontrols-slider-custom.png
912 {Custom styled slider}
913
914 \snippet qtquickcontrols-slider-custom.qml file
915
916
917 \section2 Customizing SpinBox
918
919 SpinBox consists of four visual items: \l {Control::background}{background},
920 \l {Control::}{contentItem}, \l {SpinBox::up.indicator}{up indicator},
921 and \l {SpinBox::down.indicator}{down indicator}.
922
923 \image qtquickcontrols-spinbox-custom.png
924 {Custom styled spin box}
925
926 \snippet qtquickcontrols-spinbox-custom.qml file
927
928
929 \section2 Customizing SplitView
930
931 SplitView consists of a visual \l {SplitView::handle}{handle} delegate.
932
933 \image qtquickcontrols-splitview-custom.png
934 {Custom styled split view}
935
936 \snippet qtquickcontrols-splitview-custom.qml 1
937
938
939 \section2 Customizing StackView
940
941 StackView can have a visual \l {Control::background}{background}
942 item, and it allows customizing the transitions that are used for
943 push, pop, and replace operations.
944
945 \snippet qtquickcontrols-stackview-custom.qml file
946
947
948 \section2 Customizing SwipeDelegate
949
950 SwipeDelegate consists of six visual items: \l {Control::background}{background},
951 \l {Control::}{contentItem}, \l {AbstractButton::indicator}{indicator},
952 \c swipe.left, \c swipe.right, and \c swipe.behind.
953
954 \image qtquickcontrols-swipedelegate-custom.png
955 {Custom styled swipe delegate}
956
957 \snippet qtquickcontrols-swipedelegate-custom.qml file
958
959
960 \section2 Customizing SwipeView
961
962 SwipeView can have a visual \l {Control::background}{background}
963 item. The navigation is implemented by the \l {Control::}{contentItem}.
964
965 \snippet qtquickcontrols-swipeview-custom.qml file
966
967
968 \section2 Customizing Switch
969
970 Switch consists of three visual items: \l {Control::background}{background},
971 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
972
973 \image qtquickcontrols-switch-custom.png
974 {Custom styled switch}
975
976 \snippet qtquickcontrols-switch-custom.qml file
977
978 \section2 Customizing SwitchDelegate
979
980 SwitchDelegate consists of three visual items: \l {Control::background}{background},
981 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
982
983 \image qtquickcontrols-switchdelegate-custom.png
984 {Custom styled switch delegate}
985
986 \snippet qtquickcontrols-switchdelegate-custom.qml file
987
988
989 \section2 Customizing TabBar
990
991 TabBar consists of two visual items: \l {Control::background}{background},
992 and \l {Control::}{contentItem}.
993
994 \image qtquickcontrols-tabbar-custom.png
995 {Custom styled tab bar}
996
997 \snippet qtquickcontrols-tabbar-custom.qml file
998
999
1000 \section2 Customizing TabButton
1001
1002 TabButton can be customized in the same manner as
1003 \l {Customizing Button}{Button}.
1004
1005
1006 \section2 Customizing TextArea
1007
1008 TextArea consists of a \l {TextArea::background}{background} item.
1009
1010 \image qtquickcontrols-textarea-custom.png
1011 {Custom styled text area}
1012
1013 \snippet qtquickcontrols-textarea-custom.qml file
1014
1015
1016 \section2 Customizing TextField
1017
1018 TextField consists of a \l {TextField::background}{background} item.
1019
1020 \image qtquickcontrols-textfield-custom.png
1021 {Custom styled text field}
1022
1023 \snippet qtquickcontrols-textfield-custom.qml file
1024
1025
1026 \section2 Customizing ToolBar
1027
1028 ToolBar consists of one visual item: \l {Control::background}{background}.
1029
1030 \image qtquickcontrols-toolbar-custom.png
1031 {Custom styled tool bar}
1032
1033 \snippet qtquickcontrols-toolbar-custom.qml file
1034
1035
1036 \section2 Customizing ToolButton
1037
1038 ToolButton consists of two visual items: \l {Control::background}{background}
1039 and \l {Control::}{contentItem}.
1040
1041 \image qtquickcontrols-toolbutton-custom.png
1042 {Custom styled tool button}
1043
1044 \snippet qtquickcontrols-toolbutton-custom.qml file
1045
1046
1047 \section2 Customizing ToolSeparator
1048
1049 ToolSeparator consists of two visual items: \l {Control::background}{background}
1050 and \l {Control::}{contentItem}.
1051
1052 \image qtquickcontrols-toolseparator-custom.png
1053 {Custom styled tool separator}
1054
1055 \snippet qtquickcontrols-toolseparator-custom.qml file
1056
1057
1058 \section2 Customizing ToolTip
1059
1060 ToolTip consists of two visual items: \l {Popup::background}{background}
1061 and \l {Popup::}{contentItem}.
1062
1063 \quotefromfile qtquickcontrols-tooltip-custom.qml
1064 \skipto import QtQuick
1065 \printuntil import QtQuick.Controls.Basic
1066 \skipto ToolTip
1067 \printuntil }
1068 \printuntil }
1069 \printuntil }
1070
1071 \include qquicktooltip.qdocinc customize-note
1072
1073 \section2 Customizing Tumbler
1074
1075 Tumbler consists of three visual items:
1076 \l {Control::background}{background},
1077 \l {Control::}{contentItem}, and
1078 \l {Tumbler::delegate}{delegate}.
1079
1080 \image qtquickcontrols-tumbler-custom.png
1081 {Custom styled tumbler}
1082
1083 \snippet qtquickcontrols-tumbler-custom.qml file
1084
1085 If you want to define your own contentItem, use either a \l ListView or
1086 \l PathView as the root item. For a wrapping Tumbler, use PathView:
1087
1088 \snippet qtquickcontrols-tumbler-pathView.qml contentItem
1089
1090 For a non-wrapping Tumbler, use ListView:
1091
1092 \snippet qtquickcontrols-tumbler-listView.qml contentItem
1093
1094 \section2 Customizing TableViewDelegate
1095
1096 TableViewDelegate inherits \l ItemDelegate, which means that it's composed of two
1097 visual items:
1098 \l [QML]{Control::}{background} and
1099 \l [QML]{Control::}{contentItem}.
1100
1101 You can always assign your own custom edit delegate to
1102 \l [QML]{TableView::}{editDelegate} if you have needs
1103 outside what the default edit delegate offers.
1104
1105 \image qtquickcontrols-tableviewdelegate-custom.png
1106 {Custom styled table view delegate}
1107
1108 \snippet qtquickcontrols-tableviewdelegate-custom.qml delegate
1109
1110 \section2 Customizing HeaderViewDelegate
1111
1112 HeaderViewDelegate inherits \l TableViewDelegate, which means that it's
1113 composed of two items:
1114 \l [QML]{Control::}{background} and
1115 \l [QML]{Control::}{contentItem}.
1116 You can always customize them with any arbitrary items.
1117
1118 \image qtquickcontrols-headerviewdelegate-custom.png
1119 {Custom styled header view delegate}
1120
1121 Here is an example of customizing the horizontal header view delegate:
1122
1123 \snippet qtquickcontrols-headerviewdelegate-custom.qml horizontal-delegate
1124
1125 Here is an example of customizing the vertical header view delegate:
1126
1127 \snippet qtquickcontrols-headerviewdelegate-custom.qml vertical-delegate
1128
1129 \section1 Styling Controls using StyleKit
1130
1131 The \l{Qt Labs StyleKit} module provides a set of QML types for styling
1132 Qt Quick Controls, built on top of \l{Qt Quick Templates 2}.
1133 It lets you define a complete visual style for
1134 all your controls from a single Style object, including support for
1135 themes, state-based styling, and transitions. StyleKit handles the
1136 underlying template implementation automatically, letting you focus
1137 purely on visual aspects such as colors, dimensions, borders, and shadows.
1138
1139 The \l{Qt Labs StyleKit} module is a Technology Preview module in
1140 Qt 6.11.
1141
1142*/