QML 基礎類型 point
point 類型是具有x, y 屬性的數據結果。用於表示平面的一個點。
import QtQuick 2.0
Rectangle { // 基本類型,生成一個矩形
width: 360 //矩形寬
height: 360 //矩形高
color: "lightblue" //矩形內部顏色
property point leftTop: Qt.point(90, 90) //定義一個點並初始化
Rectangle { // 以參數leftTop 數值繪製rect
x: leftTop.x
y: leftTop.y
width: 180
height: 180
color: "black"
Text { //現實hello world
anchors.centerIn: parent
id: helloWorld
color: "red"
text: qsTr("Hello World!")
}
}
MouseArea { //鼠標有效區域
anchors.fill: parent // 有效區域爲矩形區域(也就是他的父對象
onClicked: { //響應鼠標點擊
console.log(leftTop.x, leftTop.y) // 打印log
Qt.quit()
}
}
}