QML属性简介 三

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
}

 

posted @ 2016-06-24 14:43  Dkma像疯子一样战斗  阅读(2810)  评论(0编辑  收藏  举报