1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the documentation of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
48 //! [inherited properties]
49 width: 320; height: 240
52 //! [inherited properties]
54 //! [custom properties]
56 property real area: 100.45
57 //! [custom properties]
61 property real volume: 100.45
62 property date today: "2011-01-01"
63 property color background: "yellow"
67 //! [grouped properties]
76 font {pixelSize: 12; bold: true}
78 //! [grouped properties]
81 //! [property binding]
85 //! [property binding]
87 //! [property assignment]
89 Component.onCompleted: {
93 //! [property assignment]
103 property real brightness
105 //! [binding element]
108 property: "brightness"
111 //! [binding element]
114 //placeholder warning
118 //! [PropertyChanges element]
130 //! [PropertyChanges element]
136 State {name: "FETCH"},
137 State {name: "DECODE"},
138 State {name: "EXECUTE"}
142 //! [single property]
145 states: State {name: "RUNNING"}
147 //! [single property]
151 //! [print list property]
152 Component.onCompleted: console.log (multistate.states[0].name)
153 //! [print list property]
156 //! [JavaScript sample]
157 function calculateArea(width, height) {
158 return (width * height) * 0.5
162 width: 150; height: 75
163 property real area: calculateArea(width, height)
164 property real parentArea: calculateArea(parent.width,parent.height)
165 color: { if (area > parentArea) "blue"; else "red" }
167 //! [JavaScript sample]
172 width: 100; height: 100
174 width: parent.width; height: parent.height
178 width: container.width; height: container.height
182 //! [default property]
190 //without default property
199 //! [default property]
220 Gradient { //not a child of parentrectangle
222 //generates a TypeError
223 //Component.onCompleted: console.log(parent.width)
226 //child of parentrectangle
227 Rectangle {property string name: "childrectangle"}
229 //prints "childrectangle"
230 Component.onCompleted: console.log(children[0].name)
234 //! [list attached property]
239 color: ListView.isCurrentItem ? "red" : "blue"
243 delegate: listdelegate
245 //! [list attached property]
247 //! [attached signal handler]
249 Keys.onPressed: console.log("Key Press Detected")
250 Component.onCompleted: console.log("Completed initialization")
252 //! [attached signal handler]
257 buttonLabel: "Click Me!"
264 buttonImage.source: "http://qt.nokia.com/logo.png"
265 buttonLabel: buttonImage.source
273 property alias widgetLabel: label
275 //will generate an error
276 //widgetLabel.text: "Initial text"
278 //will generate an error
279 //property alias widgetLabelText: widgetLabel.text
281 Component.onCompleted: widgetLabel.text = "Alias completed Initialization"
290 property alias color: bluerectangle.color
298 Component.onCompleted: {
299 console.log (coloredrectangle.color) //prints "#1234ff"
301 console.log (coloredrectangle.color) //prints "#111111"
302 coloredrectangle.color = "#884646"
303 console.log (coloredrectangle.color) //prints #884646
306 //internal function that has access to internal properties
307 function setInternalColor() {