I’m trying to change parent and anchor at the same time, while animating the anchor change (Qt 5.0.1, Windows):
import QtQuick 2.0
Item {
id: topItem
width: 200; height: 200
Rectangle {
id: redRect
width: 100; height: 100
x: 20
y: 20
color: "red"
}
Rectangle {
id: blueRect
width: 50; height: 50
color: "blue"
anchors { top: redRect.top; left: redRect.right }
states: State {
name: "reparented"
AnchorChanges { target: blueRect; anchors.left: redRect.left; }
ParentChange { target: blueRect; parent: redRect; }
}
transitions: Transition {
ParentAnimation { via: topItem }
AnchorAnimation { duration: 1000 }
}
MouseArea {
anchors.fill: parent;
onClicked: blueRect.state = "reparented"
}
}
}
The blue box doesn’t move to the new position immediately, but jumps to the right first, then moves to the proper position according to the animation; removing ParentAnimation { via: topItem } doesn’t fix anything.
I’m doing it because ParentAnimation is limited to x,y animation only, but I want to change the parent as well. If I try to change the parent afterwords, it doesn’t work either:
Item {
id: topItem
width: 200; height: 200
Rectangle {
id: redRect
width: 100; height: 100
x: 20
y: 20
color: "red"
}
Rectangle {
id: blueRect
width: 50; height: 50
color: "blue"
anchors { top: redRect.top; left: redRect.right }
states: State {
name: "reparented"
AnchorChanges { target: blueRect; anchors.left: redRect.left; }
}
transitions: Transition {
SequentialAnimation{
AnchorAnimation { duration: 1000 }
ScriptAction{ script: blueRect.parent = redRect }
}
}
MouseArea {
anchors.fill: parent;
onClicked: blueRect.state = "reparented"
}
}
}
After a correct animation the blue box jumps down. If I remove ScriptAction{ script: blueRect.parent = redRect } it works as expected, but the parent is not changed then.
I would like to ask if it is a bug or am I doing something wrong? And how should I actually do it correctly?
↧