分类: WINDOWS
2011-09-02 15:54:23
{
width: 320; height: 240 // 立即数绑定,固有属性
color: "lightblue"
focus: true
property int counter // 定义新的属性,不绑定
property real area: 100.45 // 定义新的属性,绑定
} {
width: parent.width
}function calculateArea(width, height) { return (width * height) * 0.5 } { width: 150; height: 75 property real area: calculateArea(width, height) property real parentArea: calculateArea(parent.width,parent.height) color: { if (area > parentArea) "blue"; else "red" } }
{
Component.onCompleted: {
width = 150
}
} {
id: container
width: 100; height: 100
{
width: parent.width; height: parent.height
}
}
{
width: container.width; height: container.height
} {
id: parentrectangle
gradient:
Gradient { //not a child of parentrectangle
//generates a TypeError
//Component.onCompleted: console.log(parent.width)
}
//child of parentrectangle
{property string name: "childrectangle"}
//prints "childrectangle"
Component.onCompleted: console.log(children[0].name)
} {
id: listdelegate
{
text: "Hello"
color: ListView.isCurrentItem ? "red" : "blue"
}
}
{
delegate: listdelegate
} {
Keys.onPressed: console.log("Key Press Detected")
Component.onCompleted: console.log("Completed initialization")
} {
id: multistate
states: [
{name: "FETCH"},
{name: "DECODE"},
{name: "EXECUTE"}
]
} {
id: monostate
states: State {name: "RUNNING"}
} {
//dot notation
font.pixelSize: 12
font.bold: true
}
{
//group notation
font {pixelSize: 12; bold: true}
}property alias buttonLabel: label.text { id: label text: "empty label" }
Button { id: textbutton buttonLabel: "Click Me!" }
{
property alias buttonImage: image
Image {id: image}
}Button { id: imagebutton buttonImage.source: "" buttonLabel: buttonImage.source }
import QtQuick 1.0
{
width: 310; height: 170 // 整个可视范围的size
{
anchors.horizontalCenter: parent.horizontalCenter // 定义了随父窗口变化的行为
anchors.verticalCenter: parent.verticalCenter // 同上
spacing: 5 // column 的每个元素间的空白
{ color: "lightblue"; radius: 10.0
width: 300; height: 50
{ anchors.centerIn: parent
font.pointSize: 24; text: "Books" } }
{ color: "gold"; radius: 10.0
width: 300; height: 50
{ anchors.centerIn: parent
font.pointSize: 24; text: "Music" } }
{ color: "lightgreen"; radius: 10.0
width: 300; height: 50
{ anchors.centerIn: parent
font.pointSize: 24; text: "Movies" } }
}
}import QtQuick 1.0
{
width: 112; height: 112
color: "#303030"
{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
columns: 2
spacing: 6
{ color: "#aa6666"; width: 50; height: 50 }
{ color: "#aaaa66"; width: 50; height: 50 }
{ color: "#9999aa"; width: 50; height: 50 }
{ color: "#6666aa"; width: 50; height: 50 }
}
} import QtQuick 1.0
{
color: "lightblue"
width: 300; height: 200
{
anchors.fill: parent
anchors.margins: 4
spacing: 10
{ text: "Text"; font.pixelSize: 40 }
{ text: "items"; font.pixelSize: 40 }
{ text: "flowing"; font.pixelSize: 40 }
{ text: "inside"; font.pixelSize: 40 }
{ text: "a"; font.pixelSize: 40 }
{ text: "Flow"; font.pixelSize: 40 }
{ text: "item"; font.pixelSize: 40 }
}
} import QtQuick 1.0
{
width: 400; height: 400; color: "black"
{
x: 5; y: 5
rows: 5; columns: 5; spacing: 10
{ model: 24
{ width: 70; height: 70
color: "lightgreen"
{ text: index
font.pointSize: 30
anchors.centerIn: parent } }
}
}
}
Rectangle { id: rect1; ... }
Rectangle { id: rect2; anchors.left: rect1.right; ... }
Item {
id: group1
Rectangle { id: rect1; ... }
}
Item {
id: group2
Rectangle { id: rect2; anchors.left: rect1.right; ... } // invalid anchor!
}