qml中,普通的屬性,需要添加屬性名稱,屬性內容,如
color: “red”
默認屬性則可以直接書寫,去掉方括號,在寫重用的QML組件式比較有用,例如將一個QmL外部資源封裝好,內部具體的item,有子對象去填充。見代碼
MyColumn.qml文件:
import QtQuick 2.0
Item
{
default property alias col: myCol.children
Column {
id:myCol
anchors.fill: parent
}
}
main文件:
import QtQuick 2.2
Rectangle {
id:root
width: 860
height: 860
MyColumn
{
anchors.fill: parent
Rectangle
{
color:"red"
width: 100; height:100
}
Rectangle
{
color:"green"
width: 100; height:200
}
Rectangle
{
color:"blue"
width: 100; height:100
}
}
}
參考:http://developer.blackberry.com/native/documentation/cascades/ui/custom_components/