QML Qt Quick Study Note --- No.1
Qt Quick 與QML 關(guān)系 與 C++ 與 STL的關(guān)系 類似
qmlscene 使用
qmlscene 是用于測(cè)試QML應(yīng)用的,請(qǐng)勿使用于生產(chǎn)環(huán)境
qmlscene --help
qmlscene xxx.qml
QML 屬性
屬性名的首字母一般以小寫開始
基本類型:int real bool string color list font...
許多擴(kuò)展類型:QtObject Component onnections Binding...
QML 對(duì)象屬性是有類型安全檢測(cè)的,也就是說,你只能指定與屬性類型匹配的值,否則會(huì)報(bào)錯(cuò)
id屬性
在同一個(gè)QML文件中,不同對(duì)象的id屬性的值不能重復(fù),id屬性的值,首字符必須是小寫字母或下劃線,只能由字母,數(shù)字及下劃線組成
列表屬性
QML對(duì)象的列表屬性,類型是list, 與Array數(shù)組是類似的例:
Item {
children:[ //列表是包含在[ ] 里的,只有當(dāng)元素個(gè)數(shù)為1時(shí),[ ] 才可以省略, 建議一直保留
Image{
id: image_example
text: "txt_image"
}, //列表對(duì)象以 , 隔開
Text{
id: text_example
text: "_txt_example"
}
Button{
id: btn_example
text: txt_button
onClicked: { //信號(hào)處理
Qt.quit()
}
}
]
Component.onCompleted: { //附加信號(hào)處理器
for (var i = 0; i < children.length; ++i) {
console.log("text of label", i, ": ", children[i].text);
}
}
}
分組屬性
Text {
font.pixelSize: 19;
font.bold: true;
}
<=======>
Text {
font {
pixelSize: 19;
bold: true;
}
}
附加屬性
Item {
focus: true;
Keys.enabled: false; //此為附屬性
}
浙公網(wǎng)安備 33010602011771號(hào)