aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/qmltypereference.qdoc
blob: 799945fa37b9e38f476d772abbf6fd32c5eb338f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.  Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\qmlmodule QtQml 2
\title Qt QML QML Types
\ingroup qmlmodules
\brief List of QML types provided by the Qt QML module

The \c QtQml module provides the definition and implementation of various
convenience types which can be used with the QML language, including some
elementary QML types which can provide the basis for further extensions to the
QML language.

The \c QtQml module provides the \c QtObject and \c Component object types
which may be used in QML documents.  These types are non-visual and provide
building-blocks for extensions to QML.

\section1 Importing QtQml

The types provided by the \c QtQml module are only available in a QML document
if that document imports the \c QtQml namespace (or if the document imports the
\c QtQuick namespace, as noted below).

The current version of the \c QtQml module is version 2.0, and thus it may be
imported via the following statement:

\qml
import QtQml 2.0
\endqml

Most clients will never need to use the \c QtQml import, as all of the types
and functionality provided by the \c QtQml namespace are also provided by the
\c QtQuick namespace which may be imported as follows:

\qml
import QtQuick 2.0
\endqml

See the \l{Qt Quick} module documentation for more information about the
\c QtQuick namespace and what it provides to QML application developers.

The documentation for the types below applies equally to the types of the same
name provided by the \l{Qt Quick} module, as they are in fact identical.

\section1 Basic Types

The following \l{qtqml-typesystem-basictypes.html}{QML basic types} are
provided:

\annotatedlist qtqmlbasictypes

\section1 Object Types

The following \l{qtqml-typesystem-objecttypes.html}{QML object types} are
provided:

\section2 QtObject

The \c QtObject type provides a basic instantiable object which can be used in
QML applications.  It is non-visual, but may have properties, methods, signals
and signal handlers.

For example, the following QtObject has several properties, one of which has
been assigned a \l{Property Binding}
{binding}, and a \l{Signal and Handler Event System}{signal handler} for
the default change signal which exists for one of its properties:

\code
    import QtQuick 2.0

    QtObject {
        property int a: 15
        property int b: a + 22
        property int changeCount: 0

        onAChanged: {
            changeCount += 1;
        }
    }
\endcode

\section2 Component

The \c Component type provides a basic re-usable component which allows
instances of another type to be instantiated on-demand.  It may be given an
\c id and it has a default property which is the object type to instantiate,
but no other properties may be added to it.

For example, the following QtObject has two different \l Component
properties, and it uses those components to dynamically construct objects at
run-time:

\code
    import QtQuick 2.0

    QtObject {
        id: root
        property bool which: true

        property Component a: Component {
            id: firstComponent
            QtObject {
                property int answer: 42
                function activate() {
                    console.log("The answer is: " + answer);
                }
            }
        }

        property Component b: Component {
            id: secondComponent
            QtObject {
                property string message: "Hello, World!"
                function activate() {
                    console.log(message);
                }
            }
        }

        function activateDynamicObject() {
            var o = {};
            if (which) {
                which = false;
                o = a.createObject(null); // no parent
            } else {
                which = true;
                o = b.createObject(null); // no parent
            }
            o.activate();
        }
    }
\endcode
*/

/*!
\qmlbasictype date
\ingroup qtqmlbasictypes
\ingroup qtquickbasictypes
\brief a date value.

The \c date type refers to a date value.

To create a \c date value, specify it as a "YYYY-MM-DD" string:

\qml
MyDatePicker { minDate: "2000-01-01"; maxDate: "2020-12-31" }
\endqml

To read a date value returned from a C++ extension class, use
\l{QML:Qt::formatDate()}{Qt.formatDate()} and \l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.

When integrating with C++, note that any QDate value
\l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
converted into a \c date value, and vice-versa.

Note that the date type has comparison semantics which match
those of the JavaScript Date object.  To compare the value
of two date properties, you should compare their "toString()"
values.

This basic type is provided by the QML language.

\sa {QML Basic Types}
*/

/*!
\qmlbasictype time
\ingroup qtqmlbasictypes
\ingroup qtquickbasictypes
\brief a time value.

The \c time type refers to a time value.

To create a \c time value, specified as "hh:mm:ss":

\qml
MyTimePicker { time: "14:22:15" }
\endqml

To read a time value returned from a C++ extension class, use
\l{QML:Qt::formatTime()}{Qt.formatTime()} and \l{QML:Qt::formatDateTime()}{Qt.formatDateTime()}.

Note that when converting historical times to and from javascript that QDateTime and the JS Date object
have different methods of calculating historical daylight savings time application. This can lead to variations of one hour
when converting to historical local time.

When integrating with C++, note that any QTime value
\l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
converted into a \c time value, and vice-versa.

This basic type is provided by the QML language.

\sa {QML Basic Types}
*/

/*!
\qmlbasictype point
\ingroup qtqmlbasictypes
\ingroup qtquickbasictypes
\brief a value with x and y attributes.

The \c point type refers to a value with \c x and \c y attributes.

To create a \c point value, specify it as a "x,y" string:

\qml
CustomObject { myPointProperty: "0,20" }
\endqml

Or use the \l{QML:Qt::point()}{Qt.point()} function:

\qml
CustomObject { myPointProperty: Qt.point(0, 20) }
\endqml

When integrating with C++, note that any QPoint or QPointF value
\l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
converted into a \c point value. When a \c point value is passed to C++, it
is automatically converted into a QPointF value.

\sa{QML Basic Types}
*/

/*!
\qmlbasictype size
\ingroup qtqmlbasictypes
\ingroup qtquickbasictypes
\brief a value with width and height attributes

The \c size type refers to a value with has \c width and \c height attributes.

For example, to read the \c width and \c height values of the
\l {Image::sourceSize} size-type property:

\qml
Column {
    Image { id: image; source: "logo.png" }
    Text { text: image.sourceSize.width + "," + image.sourceSize.height }
}
\endqml

To create a \c size value, specify it as a "width x height" string:

\qml
Image { sourceSize: "150x50" }
\endqml

Or use the \l{QML:Qt::size()}{Qt.size()} function:

\qml
Image { sourceSize: Qt.size(150, 50) }
\endqml

When integrating with C++, note that any QSize or QSizeF value
\l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
converted into a \c size value, and vice-versa. When a \c size value is passed to C++, it
is automatically converted into a QSizeF value.

\sa{QML Basic Types}
*/

/*!
\qmlbasictype rect
\ingroup qtqmlbasictypes
\ingroup qtquickbasictypes
\brief a value with x, y, width and height attributes.

The \c rect type refers to a value with \c x, \c y, \c width and \c height attributes.

For example, to read the \c width and \c height values of the \l Item
\l {Item::childrenRect.x}{childrenRect} rect-type type property:

\qml
Rectangle {
    width: childrenRect.width
    height: childrenRect.height

    Rectangle { width: 100; height: 100 }
}
\endqml

To create a \c rect value, specify it as a "x, y, width x height" string:

\qml
CustomObject { myRectProperty: "50,50,100x100" }
\endqml

Or use the \l{QML:Qt::rect()}{Qt.rect()} function:

\qml
CustomObject { myRectProperty: Qt.rect(50, 50, 100, 100) }
\endqml

When integrating with C++, note that any QRect or QRectF value
\l{qtqml-cppintegration-data.html}{passed into QML from C++} is automatically
converted into a \c rect value, and vice-versa. When a \c rect value is passed to C++, it
is automatically converted into a QRectF value.

\sa{QML Basic Types}
*/