我有一个对象,我希望每次设置该特定状态时都从之前设置的位置移动。我已经尝试制作一个名为xPos的独立属性来解决绑定循环错误,该错误是在状态设置后由对象的x的新位置设置的,然后进入默认状态,以便能够再次切换回该特定状态因为调用同一个状态什么都不做,但它似乎不起作用。QML:如何使用状态从上一个设置位置移动对象
这里是我的代码片段:
property int xPos: 0
states: [
State {
name: "nextStep"
PropertyChanges {
target: progressBar_Id
x: -1*(progressBar_Id.step.width) + xPos
}
},
State {
name: "previousStep"
PropertyChanges {
target: progressBar_Id
x: progressBar_Id.step.width + xPos
}
},
State {
name: "default"
PropertyChanges {
target: progressBar_Id
x: xPos
}
}
]
transitions: [
Transition {
from: "*"
to: "nextStep"
NumberAnimation {properties: "x"; easing.type: Easing.Linear; duration: 1000}
onRunningChanged: {
if(!running) {
xPos = progressBar_Id.x;
console.info("xPos = " + xPos);
state = "default";
}
}
},
Transition {
from: "*"
to: "previousStep"
NumberAnimation {properties: "x"; easing.type: Easing.Linear; duration: 1000}
onRunningChanged: {
if(!running) {
xPos = progressBar_Id.x;
console.info("xPos = " + xPos);
state = "default";
}
}
}
]
XPOS似乎得到设定从控制台输出的第一次,但从未应用于新XCOORD对象。