summaryrefslogtreecommitdiffstats
path: root/doc/src/declarative/qdeclarativeintro.qdoc
diff options
context:
space:
mode:
authorDavid Boddie <david.boddie@nokia.com>2010-12-09 18:41:10 (GMT)
committerDavid Boddie <david.boddie@nokia.com>2010-12-09 18:41:10 (GMT)
commit4b8b0321828bd1175534ff3b883956c5b97f9399 (patch)
treea7e5f74e36caf370f03135e34c6dc2958bbdc1f5 /doc/src/declarative/qdeclarativeintro.qdoc
parent297da17b94df6cd4a3b0c4ade56baf55310939e8 (diff)
downloadQt-4b8b0321828bd1175534ff3b883956c5b97f9399.zip
Qt-4b8b0321828bd1175534ff3b883956c5b97f9399.tar.gz
Qt-4b8b0321828bd1175534ff3b883956c5b97f9399.tar.bz2
Doc: Temporarily used \qml...\endqml markup for the QML introduction.
Diffstat (limited to 'doc/src/declarative/qdeclarativeintro.qdoc')
-rw-r--r--doc/src/declarative/qdeclarativeintro.qdoc75
1 files changed, 32 insertions, 43 deletions
diff --git a/doc/src/declarative/qdeclarativeintro.qdoc b/doc/src/declarative/qdeclarativeintro.qdoc
index 4e41fda..299ec73 100644
--- a/doc/src/declarative/qdeclarativeintro.qdoc
+++ b/doc/src/declarative/qdeclarativeintro.qdoc
@@ -45,7 +45,7 @@ technologies like HTML and CSS, but it's not required.
QML looks like this:
-\code
+\qml
import QtQuick 1.0
Rectangle {
@@ -58,7 +58,7 @@ Rectangle {
anchors.centerIn: parent
}
}
-\endcode
+\endqml
Objects are specified by their type, followed by a pair of braces. Object
types always begin with a capital letter. In the above example, there are
@@ -71,18 +71,18 @@ value \c "pics/logo.png". The property and its value are separated by a colon.
Properties can be specified one-per-line:
-\code
+\qml
Rectangle {
width: 100
height: 100
}
-\endcode
+\endqml
or you can put multiple properties on a single line:
-\code
+\qml
Rectangle { width: 100; height: 100 }
-\endcode
+\endqml
When multiple property/value pairs are specified on a single line, they
must be separated by a semicolon.
@@ -96,17 +96,17 @@ and \l Image elements would not be available.
In addition to assigning values to properties, you can also assign
expressions written in JavaScript.
-\code
+\qml
Rotation {
angle: 360 * 3
}
-\endcode
+\endqml
These expressions can include references to other objects and properties, in which case
a \e binding is established: when the value of the expression changes, the property the
expression has been assigned to is automatically updated to that value.
-\code
+\qml
Item {
Text {
id: text1
@@ -117,7 +117,7 @@ Item {
text: text1.text
}
}
-\endcode
+\endqml
In the example above, the \c text2 object will display the same text as \c text1. If \c text1 is changed,
\c text2 is automatically changed to the same value.
@@ -142,12 +142,12 @@ your QML files.
Comments can also be used to prevent the execution of code, which is
sometimes useful for tracking down problems.
-\code
+\qml
Text {
text: "Hello world!"
//opacity: 0.5
}
-\endcode
+\endqml
In the above example, the Text object will have normal opacity, since the
line opacity: 0.5 has been turned into a comment.
@@ -164,14 +164,14 @@ Properties begin with a lowercase letter (with the exception of \l{Attached Prop
QML supports properties of many types (see \l{QML Basic Types}). The basic types include int,
real, bool, string, color, and lists.
-\code
+\qml
Item {
x: 10.5 // a 'real' property
- ...
+ // ...
state: "details" // a 'string' property
focus: true // a 'bool' property
}
-\endcode
+\endqml
QML properties are what is known as \e type-safe. That is, they only allow you to assign a value that
matches the property type. For example, the \c x property of item is a real, and if you try to assign
@@ -193,7 +193,7 @@ The first Rectangle element below has an \e id, "myRect". The second Rectangle e
own width by referring to \tt myRect.width, which means it will have the same \tt width
value as the first Rectangle element.
-\code
+\qml
Item {
Rectangle {
id: myRect
@@ -205,7 +205,7 @@ Item {
height: 200
}
}
-\endcode
+\endqml
Note that an \e id must begin with a lower-case letter or an underscore, and cannot contain characters other than letters, numbers and underscores.
@@ -214,24 +214,24 @@ Note that an \e id must begin with a lower-case letter or an underscore, and can
List properties look like this:
-\code
+\qml
Item {
children: [
Image {},
Text {}
]
}
-\endcode
+\endqml
The list is enclosed in square brackets, with a comma separating the
list elements. In cases where you are only assigning a single item to a
list, you can omit the square brackets:
-\code
+\qml
Image {
children: Rectangle {}
}
-\endcode
+\endqml
Items in the list can be accessed by index. See the \l{list}{list type} documentation
for more details about list properties and their available operations.
@@ -243,23 +243,23 @@ Each object type can specify one of its list or object properties as its default
If a property has been declared as the default property, the property tag can be omitted.
For example this code:
-\code
+\qml
State {
changes: [
PropertyChanges {},
PropertyChanges {}
]
}
-\endcode
+\endqml
can be simplified to:
-\code
+\qml
State {
PropertyChanges {}
PropertyChanges {}
}
-\endcode
+\endqml
because \c changes is the default property of the \c State type.
@@ -294,18 +294,7 @@ are of the form \e {Type.property} where \e Type is the type of the
element that attaches \e property.
For example:
-\code
-Component {
- id: myDelegate
- Text {
- text: "Hello"
- color: ListView.isCurrentItem ? "red" : "blue"
- }
-}
-ListView {
- delegate: myDelegate
-}
-\endcode
+\snippet doc/src/snippets/declarative/introduction-qml/attachedproperties1.qml component and list view
The \l ListView element attaches the \e ListView.isCurrentItem property
to each delegate it creates.
@@ -314,12 +303,12 @@ Another example of attached properties is the \l Keys element which
attaches properties for handling key presses to
any visual Item, for example:
-\code
+\qml
Item {
focus: true
Keys.onSelectPressed: console.log("Selected")
}
-\endcode
+\endqml
\section2 Signal Handlers
@@ -327,23 +316,23 @@ Signal handlers allow actions to be taken in response to an event. For instance
the \l MouseArea element has signal handlers to handle mouse press, release
and click:
-\code
+\qml
MouseArea {
onPressed: console.log("mouse button pressed")
}
-\endcode
+\endqml
All signal handlers begin with \e "on".
Some signal handlers include an optional parameter, for example
the MouseArea onPressed signal handler has a \e mouse parameter:
-\code
+\qml
MouseArea {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: if (mouse.button == Qt.RightButton) console.log("Right mouse button pressed")
}
-\endcode
+\endqml
*/