1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 | /*!
|
---|
31 | \page qml-intro.html
|
---|
32 | \title Intro to Qt Quick
|
---|
33 |
|
---|
34 | \section1 Overview
|
---|
35 |
|
---|
36 | QML is a high level, scripted language. Its commands, more correctly \e elements,
|
---|
37 | leverage the power and efficiency of the Qt libraries to make easy to use
|
---|
38 | commands that perform intuitive functions. Draw a rectangle, display an image at
|
---|
39 | a position and so on. Behind these elements are complex C++ libraries that
|
---|
40 | efficiently perform the action. As with any graphical application, always
|
---|
41 | consider that this ability to easily build graphically rich applications means
|
---|
42 | that some care may be needed to prevent performance problems.
|
---|
43 |
|
---|
44 | The language also allows more flexibility of these commands by using
|
---|
45 | Javascript rather than C++ to add new layers of logic to your application.
|
---|
46 | Javascript is easier to learn than C++ and can be embedded into the QML
|
---|
47 | files or imported from a separate file.
|
---|
48 |
|
---|
49 | \bold{In QML the types of various 'objects' are referred to as \l {QML
|
---|
50 | Elements}{elements}}.
|
---|
51 |
|
---|
52 | An element usually has various \e properties that help define the element. For
|
---|
53 | example, if we created an element called Circle then the radius of the circle
|
---|
54 | would be a property.
|
---|
55 |
|
---|
56 |
|
---|
57 | \section1 A First Look
|
---|
58 |
|
---|
59 | The basic syntax of an \l{QML Elements}{element} is
|
---|
60 |
|
---|
61 | \qml
|
---|
62 | SomeElement {
|
---|
63 | id: myObject
|
---|
64 | ... some other things here ...
|
---|
65 | }
|
---|
66 | \endqml
|
---|
67 |
|
---|
68 | Here we are defining a new object. We specify its 'type' first as SomeElement.
|
---|
69 | Then within matching braces { ... } we specify the various parts of our
|
---|
70 | element.
|
---|
71 |
|
---|
72 | The \c id is a unique identifier for the element, it must start with a lower
|
---|
73 | case letter and only contain letters, numbers and underscores. It is this
|
---|
74 | particular object's name. If this SomeElement \l {QML Elements}{element} was
|
---|
75 | a Rectangle instead and it was one of many then the \e optional unique id
|
---|
76 | would allow us to manipulate each element individually.
|
---|
77 |
|
---|
78 | Each visual element is ultimately based on, or inherits from, an element
|
---|
79 | called \l Item. \l Item has certain properties and actions that may be
|
---|
80 | useful. The properties have default values so you need only specify the
|
---|
81 | ones you will need.
|
---|
82 |
|
---|
83 | Take a simple element such as a \l Rectangle. It has an \c id, we will call
|
---|
84 | it \e myRectangle, it has a \c width and a \c height. Imagine that we
|
---|
85 | want a rectangle that is 500 pixels by 400 pixels in the x and y directions
|
---|
86 | (horizontal by vertical).
|
---|
|
---|