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 \section2 Customizing ApplicationWindow
555
556 ApplicationWindow consists of one visual item:
557 \l {ApplicationWindow::background}{background}.
558
559 \qml
560 import QtQuick
561 import QtQuick.Controls.Basic
562
563 ApplicationWindow {
564 visible: true
565
566 background: Rectangle {
567 gradient: Gradient {
568 GradientStop { position: 0; color: "#ffffff" }
569 GradientStop { position: 1; color: "#c1bbf9" }
570 }
571 }
572 }
573 \endqml
574
575
576 \section2 Customizing BusyIndicator
577
578 BusyIndicator consists of two visual items: \l {Control::background}{background}
579 and \l {Control::}{contentItem}.
580
581 \image qtquickcontrols-busyindicator-custom.png
582 {Custom styled busy indicator}
583
584 \snippet qtquickcontrols-busyindicator-custom.qml file
585
586
587 \section2 Customizing Button
588
589 Button consists of two visual items: \l {Control::background}{background}
590 and \l {Control::}{contentItem}.
591
592 \image qtquickcontrols-button-custom.png
593 {Custom styled button}
594
595 \snippet qtquickcontrols-button-custom.qml file
596
597
598 \section2 Customizing CheckBox
599
600 CheckBox consists of three visual items: \l {Control::background}{background},
601 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
602
603 \image qtquickcontrols-checkbox-custom.png
604 {Custom styled checkbox}
605
606 \snippet qtquickcontrols-checkbox-custom.qml file
607
608 \section2 Customizing CheckDelegate
609
610 CheckDelegate consists of three visual items: \l {Control::background}{background},
611 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
612
613 \image qtquickcontrols-checkdelegate-custom.png
614 {Custom styled check delegate}
615
616 \snippet qtquickcontrols-checkdelegate-custom.qml file
617
618
619 \section2 Customizing ComboBox
620
621 ComboBox consists of \l {Control::background}{background},
622 \l {Control::}{contentItem}, \l {ComboBox::popup}{popup},
623 \l {ComboBox::indicator}{indicator}, and \l {ComboBox::delegate}{delegate}.
624
625 \image qtquickcontrols-combobox-custom.png
626 {Custom styled combo box}
627
628 \snippet qtquickcontrols-combobox-custom.qml file
629
630 As explained in \l {ComboBox Model Roles}, ComboBox supports multiple
631 types of models.
632
633 Since \l {qml-data-models}{all the models provide an anonymous property}
634 with \c modelData, the following expression retrieves the right text in
635 all cases:
636
637 \code
638 text: model[control.textRole]
639 \endcode
640
641 When you provide a specific \c textRole and a model with structured
642 data that provides the selected role, this is expression is a regular
643 property lookup. When you provide a model with singular data, such as
644 a list of strings, and an empty \c textRole, this expression retrieves
645 the \c modelData.
646
647 \section2 Customizing DelayButton
648
649 DelayButton consists of two visual items: \l {Control::background}{background}
650 and \l {Control::}{contentItem}.
651
652 \image qtquickcontrols-delaybutton-custom.png
653 {Custom styled delay button}
654
655 \snippet qtquickcontrols-delaybutton-custom.qml file
656
657
658 \section2 Customizing Dial
659
660 Dial consists of two visual items: \l {Control::background}{background}
661 and \l {Dial::handle}{handle}.
662
663 \image qtquickcontrols-dial-custom.png
664 {Custom styled dial}
665
666 \snippet qtquickcontrols-dial-custom.qml file
667
668
669 \section2 Customizing DoubleSpinBox
670
671 DoubleSpinBox can be customized in the same manner as
672 \l {Customizing SpinBox}{Button}.
673
674
675 \section2 Customizing Drawer
676
677 Drawer can have a visual \l {Control::background}{background}
678 item.
679
680 \code
681 background: Rectangle {
682 Rectangle {
683 x: parent.width - 1
684 width: 1
685 height: parent.height
686 color: "#21be2b"
687 }
688 }
689 \endcode
690
691
692 \section2 Customizing Frame
693
694 Frame consists of one visual item: \l {Control::background}{background}.
695
696 \image qtquickcontrols-frame-custom.png
697 {Custom styled frame}
698
699 \snippet qtquickcontrols-frame-custom.qml file
700
701
702 \section2 Customizing GroupBox
703
704 GroupBox consists of two visual items: \l {Control::background}{background}
705 and \l {GroupBox::label}{label}.
706
707 \image qtquickcontrols-groupbox-custom.png
708 {Custom styled group box}
709
710 \snippet qtquickcontrols-groupbox-custom.qml file
711
712
713 \section2 Customizing ItemDelegate
714
715 ItemDelegate consists of two visual items: \l {Control::background}{background}
716 and \l {Control::}{contentItem}.
717
718 \image qtquickcontrols-itemdelegate-custom.png
719 {Custom styled item delegate}
720
721 \snippet qtquickcontrols-itemdelegate-custom.qml file
722
723
724 \section2 Customizing Label
725
726 Label can have a visual \l {Label::background}{background} item.
727
728 \image qtquickcontrols-label-custom.png
729 {Custom styled label}
730
731 \snippet qtquickcontrols-label-custom.qml file
732
733
734 \section2 Customizing Menu
735
736 \list
737 \li \l Menu consists of a visual \l {Popup::background}{background} item.
738 \li \l MenuItem consists of four visual items: \l {Control::background}{background},
739 \l {Control::}{contentItem}, \l {AbstractButton::}{indicator}, and
740 \l {MenuItem::}{arrow}.
741 \li \l MenuSeparator consists of a visual \l {Control::background}{background} and
742 \l {Control::}{contentItem}.
743 \endlist
744
745 \image qtquickcontrols-menu-custom.png
746 {Custom styled menu}
747
748 \quotefromfile qtquickcontrols-menu-custom.qml
749 \skipto import QtQuick
750 \printuntil import QtQuick.Controls.Basic
751 \skipto Menu
752 \printto eof
753
754
755 \section2 Customizing MenuBar
756
757 MenuBar can have a visual \l {Control::background}{background} item,
758 and MenuBarItem consists of two visual items: \l {Control::background}
759 {background} and \l {Control::}{contentItem}.
760
761 \image qtquickcontrols-menubar-custom.png
762 {Custom styled menu bar with File and Edit menus}
763
764 \quotefromfile qtquickcontrols-menubar-custom.qml
765 \skipto import QtQuick
766 \printuntil import QtQuick.Controls.Basic
767 \skipto MenuBar
768 \printto eof
769
770
771 \section2 Customizing PageIndicator
772
773 PageIndicator consists of a \l {Control::background}{background}, \l {Control::}{contentItem}, and \l {PageIndicator::delegate}{delegate}.
774
775 \image qtquickcontrols-pageindicator-custom.png
776 {Custom styled page indicator showing multiple pages}
777
778 \snippet qtquickcontrols-pageindicator-custom.qml file
779
780
781 \section2 Customizing Pane
782
783 Pane consists of a \l {Control::background}{background}.
784
785 \image qtquickcontrols-pane-custom.png
786 {Custom styled pane with decorative background}
787
788 \snippet qtquickcontrols-pane-custom.qml file
789
790
791 \section2 Customizing Popup
792
793 Popup consists of a \l {Popup::background}{background} and
794 \l {Popup::contentItem}{contentItem}.
795
796 \image qtquickcontrols-popup-custom.png
797 {Custom styled popup with border and shadow}
798
799 \quotefromfile qtquickcontrols-popup-custom.qml
800 \skipto import QtQuick
801 \printuntil import QtQuick.Controls.Basic
802 \codeline
803 \skipto Popup
804 \printuntil {
805 \printuntil }
806 \printuntil }
807 \printuntil }
808
809
810 \section2 Customizing ProgressBar
811
812 ProgressBar consists of two visual items: \l {Control::background}{background}
813 and \l {Control::}{contentItem}.
814
815 \image qtquickcontrols-progressbar-custom.png
816 {Custom styled progress bar showing partial completion}
817
818 \snippet qtquickcontrols-progressbar-custom.qml file
819
820 Above, the contentItem is also animated to represent an
821 \l {ProgressBar::}{indeterminate} progress bar state.
822
823
824 \section2 Customizing RadioButton
825
826 RadioButton consists of three visual items: \l {Control::background}{background},
827 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
828
829 \image qtquickcontrols-radiobutton-custom.png
830 {Custom styled radio button in selected state}
831
832 \snippet qtquickcontrols-radiobutton-custom.qml file
833
834
835 \section2 Customizing RadioDelegate
836
837 RadioDelegate consists of three visual items: \l {Control::background}{background},
838 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
839
840 \image qtquickcontrols-radiodelegate-custom.png
841 {Custom styled radio delegate in list}
842
843 \snippet qtquickcontrols-radiodelegate-custom.qml file
844
845
846 \section2 Customizing RangeSlider
847
848 RangeSlider consists of three visual items:
849 \l {Control::background}{background},
850 \l {RangeSlider::first}{first.handle} and
851 \l {RangeSlider::second.handle}{second.handle}.
852
853 \image qtquickcontrols-rangeslider-custom.png
854 {Custom styled range slider}
855
856 \snippet qtquickcontrols-rangeslider-custom.qml file
857
858
859 \section2 Customizing RoundButton
860
861 RoundButton can be customized in the same manner as
862 \l {Customizing Button}{Button}.
863
864
865 \section2 Customizing ScrollBar
866
867 ScrollBar consists of two visual items: \l {Control::background}{background}
868 and \l {Control::}{contentItem}.
869
870 \image qtquickcontrols-scrollbar-custom.png
871 {Custom styled scroll bar}
872
873 \snippet qtquickcontrols-scrollbar-custom.qml file
874
875
876 \section2 Customizing ScrollIndicator
877
878 ScrollIndicator consists of two visual items: \l {Control::background}{background}
879 and \l {Control::}{contentItem}.
880
881 \image qtquickcontrols-scrollindicator-custom.png
882 {Custom styled scroll indicator}
883
884 \snippet qtquickcontrols-scrollindicator-custom.qml file
885
886
887 \section2 Customizing ScrollView
888
889 ScrollView consists of a \l {Control::background}{background} item,
890 and horizontal and vertical scroll bars.
891
892 \image qtquickcontrols-scrollview-custom.png
893 {Custom styled scroll view}
894
895 \snippet qtquickcontrols-scrollview-custom.qml file
896
897
898 \section2 Customizing Slider
899
900 Slider consists of two visual items: \l {Control::background}{background},
901 and \l {Slider::handle}{handle}.
902
903 \image qtquickcontrols-slider-custom.png
904 {Custom styled slider}
905
906 \snippet qtquickcontrols-slider-custom.qml file
907
908
909 \section2 Customizing SpinBox
910
911 SpinBox consists of four visual items: \l {Control::background}{background},
912 \l {Control::}{contentItem}, \l {SpinBox::up.indicator}{up indicator},
913 and \l {SpinBox::down.indicator}{down indicator}.
914
915 \image qtquickcontrols-spinbox-custom.png
916 {Custom styled spin box}
917
918 \snippet qtquickcontrols-spinbox-custom.qml file
919
920
921 \section2 Customizing SplitView
922
923 SplitView consists of a visual \l {SplitView::handle}{handle} delegate.
924
925 \image qtquickcontrols-splitview-custom.png
926 {Custom styled split view}
927
928 \snippet qtquickcontrols-splitview-custom.qml 1
929
930
931 \section2 Customizing StackView
932
933 StackView can have a visual \l {Control::background}{background}
934 item, and it allows customizing the transitions that are used for
935 push, pop, and replace operations.
936
937 \snippet qtquickcontrols-stackview-custom.qml file
938
939
940 \section2 Customizing SwipeDelegate
941
942 SwipeDelegate consists of six visual items: \l {Control::background}{background},
943 \l {Control::}{contentItem}, \l {AbstractButton::indicator}{indicator},
944 \c swipe.left, \c swipe.right, and \c swipe.behind.
945
946 \image qtquickcontrols-swipedelegate-custom.png
947 {Custom styled swipe delegate}
948
949 \snippet qtquickcontrols-swipedelegate-custom.qml file
950
951
952 \section2 Customizing SwipeView
953
954 SwipeView can have a visual \l {Control::background}{background}
955 item. The navigation is implemented by the \l {Control::}{contentItem}.
956
957 \snippet qtquickcontrols-swipeview-custom.qml file
958
959
960 \section2 Customizing Switch
961
962 Switch consists of three visual items: \l {Control::background}{background},
963 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
964
965 \image qtquickcontrols-switch-custom.png
966 {Custom styled switch}
967
968 \snippet qtquickcontrols-switch-custom.qml file
969
970 \section2 Customizing SwitchDelegate
971
972 SwitchDelegate consists of three visual items: \l {Control::background}{background},
973 \l {Control::}{contentItem} and \l {AbstractButton::indicator}{indicator}.
974
975 \image qtquickcontrols-switchdelegate-custom.png
976 {Custom styled switch delegate}
977
978 \snippet qtquickcontrols-switchdelegate-custom.qml file
979
980
981 \section2 Customizing TabBar
982
983 TabBar consists of two visual items: \l {Control::background}{background},
984 and \l {Control::}{contentItem}.
985
986 \image qtquickcontrols-tabbar-custom.png
987 {Custom styled tab bar}
988
989 \snippet qtquickcontrols-tabbar-custom.qml file
990
991
992 \section2 Customizing TabButton
993
994 TabButton can be customized in the same manner as
995 \l {Customizing Button}{Button}.
996
997
998 \section2 Customizing TextArea
999
1000 TextArea consists of a \l {TextArea::background}{background} item.
1001
1002 \image qtquickcontrols-textarea-custom.png
1003 {Custom styled text area}
1004
1005 \snippet qtquickcontrols-textarea-custom.qml file
1006
1007
1008 \section2 Customizing TextField
1009
1010 TextField consists of a \l {TextField::background}{background} item.
1011
1012 \image qtquickcontrols-textfield-custom.png
1013 {Custom styled text field}
1014
1015 \snippet qtquickcontrols-textfield-custom.qml file
1016
1017
1018 \section2 Customizing ToolBar
1019
1020 ToolBar consists of one visual item: \l {Control::background}{background}.
1021
1022 \image qtquickcontrols-toolbar-custom.png
1023 {Custom styled tool bar}
1024
1025 \snippet qtquickcontrols-toolbar-custom.qml file
1026
1027
1028 \section2 Customizing ToolButton
1029
1030 ToolButton consists of two visual items: \l {Control::background}{background}
1031 and \l {Control::}{contentItem}.
1032
1033 \image qtquickcontrols-toolbutton-custom.png
1034 {Custom styled tool button}
1035
1036 \snippet qtquickcontrols-toolbutton-custom.qml file
1037
1038
1039 \section2 Customizing ToolSeparator
1040
1041 ToolSeparator consists of two visual items: \l {Control::background}{background}
1042 and \l {Control::}{contentItem}.
1043
1044 \image qtquickcontrols-toolseparator-custom.png
1045 {Custom styled tool separator}
1046
1047 \snippet qtquickcontrols-toolseparator-custom.qml file
1048
1049
1050 \section2 Customizing ToolTip
1051
1052 ToolTip consists of two visual items: \l {Popup::background}{background}
1053 and \l {Popup::}{contentItem}.
1054
1055 \quotefromfile qtquickcontrols-tooltip-custom.qml
1056 \skipto import QtQuick
1057 \printuntil import QtQuick.Controls.Basic
1058 \skipto ToolTip
1059 \printuntil }
1060 \printuntil }
1061 \printuntil }
1062
1063 \include qquicktooltip.qdocinc customize-note
1064
1065 \section2 Customizing Tumbler
1066
1067 Tumbler consists of three visual items:
1068 \l {Control::background}{background},
1069 \l {Control::}{contentItem}, and
1070 \l {Tumbler::delegate}{delegate}.
1071
1072 \image qtquickcontrols-tumbler-custom.png
1073 {Custom styled tumbler}
1074
1075 \snippet qtquickcontrols-tumbler-custom.qml file
1076
1077 If you want to define your own contentItem, use either a \l ListView or
1078 \l PathView as the root item. For a wrapping Tumbler, use PathView:
1079
1080 \snippet qtquickcontrols-tumbler-pathView.qml contentItem
1081
1082 For a non-wrapping Tumbler, use ListView:
1083
1084 \snippet qtquickcontrols-tumbler-listView.qml contentItem
1085
1086 \section2 Customizing TableViewDelegate
1087
1088 TableViewDelegate inherits \l ItemDelegate, which means that it's composed of two
1089 visual items:
1090 \l [QML]{Control::}{background} and
1091 \l [QML]{Control::}{contentItem}.
1092
1093 You can always assign your own custom edit delegate to
1094 \l [QML]{TableView::}{editDelegate} if you have needs
1095 outside what the default edit delegate offers.
1096
1097 \image qtquickcontrols-tableviewdelegate-custom.png
1098 {Custom styled table view delegate}
1099
1100 \snippet qtquickcontrols-tableviewdelegate-custom.qml delegate
1101
1102 \section2 Customizing HeaderViewDelegate
1103
1104 HeaderViewDelegate inherits \l TableViewDelegate, which means that it's
1105 composed of two items:
1106 \l [QML]{Control::}{background} and
1107 \l [QML]{Control::}{contentItem}.
1108 You can always customize them with any arbitrary items.
1109
1110 \image qtquickcontrols-headerviewdelegate-custom.png
1111 {Custom styled header view delegate}
1112
1113 Here is an example of customizing the horizontal header view delegate:
1114
1115 \snippet qtquickcontrols-headerviewdelegate-custom.qml horizontal-delegate
1116
1117 Here is an example of customizing the vertical header view delegate:
1118
1119 \snippet qtquickcontrols-headerviewdelegate-custom.qml vertical-delegate
1120*/