diff options
Diffstat (limited to 'doc/src/declarative/qdeclarativeintro.qdoc')
-rw-r--r-- | doc/src/declarative/qdeclarativeintro.qdoc | 81 |
1 files changed, 37 insertions, 44 deletions
diff --git a/doc/src/declarative/qdeclarativeintro.qdoc b/doc/src/declarative/qdeclarativeintro.qdoc index 1d807e3..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 @@ -186,14 +186,14 @@ Item { \section3 The \c id property Each object can be given a special unique property called an \e id. No other object within the -same \l{QML Documents}{QML document} can have the same \c id value. Assigning an id enables the object +same QML component (see \l{QML Documents}) can have the same \c id value. Assigning an id enables the object to be referred to by other objects and scripts. The first Rectangle element below has an \e id, "myRect". The second Rectangle element defines its 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,28 @@ 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. + \section2 Default properties @@ -239,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. @@ -290,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. @@ -310,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 @@ -323,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 */ |