Thanks moeg687. Your code indeed works, but now there is another problem: if I enable clipping on the redRectangle, changing parent via topItem doesn’t work, the blueRectangle is still being clipped against the red one:
import QtQuick 2.0
Item {
id: topItem
width: 200; height: 200
Rectangle {
id: redRect
width: 100; height: 100
clip: true
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"
ParentChange { target: blueRect; parent: redRect; }
AnchorChanges { target: blueRect; anchors.left: redRect.left; }
}
transitions: Transition {
ParentAnimation { via: topItem }
AnchorAnimation { duration: 1000 }
}
MouseArea {
anchors.fill: parent;
onClicked: blueRect.state = "reparented"
}
}
}
↧