1.QML屬性
基本類型可以查看幫助文檔中的“QML Basic Types”關鍵字;
注意:屬性總是以小寫字母開頭,且是“類型安全的”
2.QML屬性更改通知
使用信號處理器“on<Property>Changed”語法命名。比如onWidthChanged,無論何時屬性width被修改,都會自動調用該函數
Rectangle{ width:100;height:100; onWidthChanged:console.log("Width has changed": width) onHeightChanged:console.log("Height has changed": height) }
使用console.log()來輸出調試信息(同console.debug和Qt C++編程中使用qDebug())。
在QML中主要使用console.log()和console.debug()進行調試和信息輸出。
3.列表屬性
Item{ children:[ Image{}, Text{}, ... ] }
列表在一對方括號中,使用逗號分隔列表元素。
children : list<Item>
The children property contains the list of visual children of this item. The resources property contains non-visual resources that you want to reference by name.
It is not generally necessary to refer to these properties when adding child items or resources, as the default data property will automatically assign child objects to the children and resources properties as appropriate. See the data documentation for details.
列表中可以是children 也可以是其他的。
4.附加屬性
一些對象附加屬性到其他對象上。例如,ListView元素會附加ListView.isCurrentItem屬性到他的每一個delegate(委托)上:
附加屬性使用“Type.property”格式。
5.屬性綁定
使用JavaScript表達式,關聯兩個屬性之間的值。
Rectangle{ width:otherItem.width height:otherItem.height }