QML的默认属性default property

qml中,普通的属性,须要添加属性名称,属性内容,如ui

color: “red”component

默认属性则能够直接书写,去掉方括号,在写重用的QML组件式比较有用,例如将一个QmL外部资源封装好,内部具体的item,有子对象去填充。见代码对象

MyColumn.qml文件:资源

 

import QtQuick 2.0get

 
Item
{
    default property alias col: myCol.children
    Column {
        id:myCol
        anchors.fill: parent
 
    }
}
 
main文件:
 

import QtQuick 2.2it

 
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/io

相关文章
相关标签/搜索