Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtquickcontrols-qmltypes.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 \qmlmodule QtQuick.Controls
6 \keyword Qt Quick Controls QML Types
7 \title Qt Quick Controls QML Types
8 \keyword Qt Quick Controls 2 QML Types
9 \ingroup qmlmodules
10 \brief Provides QML types for user interfaces (Qt Quick Controls).
11
12 \l{Qt Quick Controls} provides QML types for creating user interfaces.
13 These QML types work in conjunction with \l{Qt Quick} and
14 \l{Qt Quick Layouts}.
15
16 Qt Quick Controls QML types can be imported into your application
17 using the following import statement in your .qml file:
18
19 \qml
20 import QtQuick.Controls
21 \endqml
22
23 \section1 QML Types
24 \generatelist {qmltypesbymodule QtQuick.Controls}
25 \noautolist
26
27 \section1 Using Qt Quick Controls types in property declarations
28
29 As mentioned in \l {Qt Quick Templates 2 QML Types}, each type in Qt Quick
30 Controls is backed by a C++ "template" type. These types are \l {Qt Quick
31 Templates 2}{non-visual implementations of controls' logic and behavior}.
32
33 For example, the \l Menu type's API and behavior is defined by the C++
34 type in Qt Quick Templates. Each \l {Definition of a Style}{style} that
35 wants to provide a Menu must have a Menu.qml available, and the root
36 item in that file must be the Menu from Qt Quick Templates. When you
37 import QtQuick.Controls and create a Menu in QML, the type you get is
38 actually the QML Menu defined by the style's Menu.qml.
39
40 In order to use a control as the type in a property declaration, you should
41 use the corresponding type from Qt Quick Templates. For example, suppose
42 you had a \c PopupOpener component, which was a Button that opened a
43 Popup:
44
45 \qml
46 // PopupButton.qml
47 import QtQuick.Controls
48
49 Button {
50 required property Popup popup
51
52 onClicked: popup.open()
53 }
54
55 // main.qml
56 PopupButton {
57 popup: saveChangesDialog
58 }
59
60 Dialog {
61 id: saveChangesDialog
62
63 // ...
64 }
65 \endqml
66
67 Running this code will result in an error:
68
69 \badcode
70 Unable to assign Dialog_QMLTYPE to Popup_QMLTYPE
71 \endcode
72
73 This is because of the inheritance hierarchy:
74
75 \badcode
76 Popup (C++ type in QtQuick.Templates)
77 │ └── Popup (QML type in QtQuick.Controls)
78 └── Dialog (C++ type in QtQuick.Templates)
79 └── Dialog (QML type in QtQuick.Controls)
80 \endcode
81
82 Dialog from \c QtQuick.Controls does not derive from the Popup from
83 \c QtQuick.Controls, but from \c QtQuick.Templates.
84
85 Instead, use the Popup from Qt Quick Templates as the property type:
86
87 \qml
88 // PopupButton.qml
89 import QtQuick.Controls
90 import QtQuick.Templates as T
91
92 Button {
93 required property T.Popup popup
94
95 onClicked: popup.open()
96 }
97 \endqml
98
99 For more information on the Qt Quick Controls module, see the
100 \l {Qt Quick Controls} module documentation.
101
102 \section1 Related Information
103 \list
104 \li \l {Qt Quick Controls Guidelines}
105 \endlist
106*/