Qt js中binding的使用
1.一个组件的属性会自动进行绑定,单设置为静态值,这种绑定关系就会被删除,如下:
Rectangle {
width: 100
height: width * 2 //该属性会和宽度自定进行绑定
focus: true
Keys.onSpacePressed: {
height = width * 3 //一旦设置为静态值,绑定关系就会删除
}
}
2.js中使用binding
Rectangle {
width: 100
height: width * 2 //建立绑定关系
focus: true
Keys.onSpacePressed: {
height = Qt.binding(function() { return width * 3 }) //重新建立绑定关系
}
}