【发布时间】:2021-01-21 17:20:56
【问题描述】:
假设属性“x”在 QML 中有一个即时值, 另一个属性 'y' 绑定到 'x'
Text { id: mytext; x: 100; y: x; text: x+","+y; }
为任何属性分配另一个值是否合法? 即绑定'y:x'只是被删除/覆盖,还是进入某种不受支持/错误的状态?
Button { onClicked: { mytext.x = 120; mytext.y = 130; } }
如果我在同一个 QML 文件中明确指定另一个绑定会怎样:
Binding { target: mytext; property: "x"; value: 140; }
Binding on y { value: 150; } //insert this line into mytext
如果指定了“when”,有什么不同吗?我可以指定多个条件绑定吗?
Binding { target: mytext; property: "x"; value: 160; when: width < 600; }
Binding { target: mytext; property: "x"; value: 170; when: width > 800; }
动画或行为有什么不同吗?
NumberAnimation on x { from: 100; to: 200; duration: 500 } //insert line into mytext
NumberAnimation { target: mytext; property: "y"; from: 100; to: 200; duration: 500 }
从 C++ 代码分配(或创建绑定)有什么不同吗?
mytextPointer->setX(190);
请注意,我不是在询问此代码是否在您的系统上工作 - 相反,我想知道此代码是否应该工作 strong> 符合预期。
我的意图是:
- “直接指定”值(x=100 和 y=x)是默认值,
- 无论何时分配它们,它们的值都会被分配的值替换
我目前对文档的理解是:
- 有多个条件绑定是可以的(只要两个条件不能同时为真?) - 在条件不再为真后,绑定恢复以前的值(不一定是默认值);
- animation/behavior/transition 在运行/活动时会覆盖绑定,但在完成后不会恢复之前的值(?);
- 其他一切都不清楚(但显然有效;如果分配了多个绑定,那么显然第一个提供了值)
【问题讨论】:
标签: qt qml qtquick2 qt-quick qtdeclarative