因为它一直表现出奇怪的行为(并导致 QMLViewer 崩溃)。
编码:
import QtQuick 1.1
Rectangle {
width: 800; height: 600
Rectangle {
width: 60; height: 60
x: rect1.x - 5; y: rect1.y - 5
color: "green"
property NumberAnimation anim: NumberAnimation {
id: animId; duration: 2000
}
Behavior on x {
animation: animId
}
Behavior on y {
animation: animId
}
}
Rectangle {
id: rect1
width: 50; height: 50
color: "red"
}
focus: true
Keys.onRightPressed: rect1.x = rect1.x + 100
Keys.onLeftPressed: rect1.x = rect1.x - 100
Keys.onUpPressed: rect1.y = rect1.y - 100
Keys.onDownPressed: rect1.y = rect1.y + 100
}
请注意该anim
属性,其值显然不是封闭元素的子元素。
这可能给我们带来了 QML 内存管理和所有权的问题(再次)。