QML Qt Quick Study Note --- No.1
Qt Quick 与QML 关系 与 C++ 与 STL的关系 类似
qmlscene 使用
qmlscene 是用于测试QML应用的,请勿使用于生产环境
qmlscene --help
qmlscene xxx.qml
QML 属性
属性名的首字母一般以小写开始
基本类型:int real bool string color list font...
许多扩展类型:QtObject Component onnections Binding...
QML 对象属性是有类型安全检测的,也就是说,你只能指定与属性类型匹配的值,否则会报错
id属性
在同一个QML文件中,不同对象的id属性的值不能重复,id属性的值,首字符必须是小写字母或下划线,只能由字母,数字及下划线组成
列表属性
QML对象的列表属性,类型是list, 与Array数组是类似的例:
Item {
children:[ //列表是包含在[ ] 里的,只有当元素个数为1时,[ ] 才可以省略, 建议一直保留
Image{
id: image_example
text: "txt_image"
}, //列表对象以 , 隔开
Text{
id: text_example
text: "_txt_example"
}
Button{
id: btn_example
text: txt_button
onClicked: { //信号处理
Qt.quit()
}
}
]
Component.onCompleted: { //附加信号处理器
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; //此为附属性
}