我有一個對象,我希望每次設置該特定狀態時都從之前設置的位置移動。我已經嘗試製作一個名爲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對象。