ParentAnimation QML Type | Qt Quick (original) (raw)

Animates changes in parent values. More...

Import Statement: import QtQuick
Inherits: Animation

Properties

Detailed Description

ParentAnimation is used to animate a parent change for an Item.

For example, the following ParentChange changes blueRect to become a child of redRect when it is clicked. The inclusion of the ParentAnimation, which defines a NumberAnimation to be applied during the transition, ensures the item animates smoothly as it moves to its new parent:

import QtQuick

Item { width: 200; height: 100

[Rectangle](qml-qtquick-rectangle.html) {
    id: redRect
    width: 100; height: 100
    color: "red"
}

[Rectangle](qml-qtquick-rectangle.html) {
    id: blueRect
    x: redRect.width
    width: 50; height: 50
    color: "blue"

    states: State {
        name: "reparented"
        [ParentChange](qml-qtquick-parentchange.html) { target: blueRect; parent: redRect; x: 10; y: 10 }
    }

    transitions: Transition {
        [ParentAnimation](qml-qtquick-parentanimation.html) {
            [NumberAnimation](qml-qtquick-numberanimation.html) { properties: "x,y"; duration: 1000 }
        }
    }

    [MouseArea](qml-qtquick-mousearea.html) { anchors.fill: parent; onClicked: blueRect.state = "reparented" }
}

}

A ParentAnimation can contain any number of animations. These animations will be run in parallel; to run them sequentially, define them within a SequentialAnimation.

In some cases, such as when reparenting between items with clipping enabled, it is useful to animate the parent change via another item that does not have clipping enabled. Such an item can be set using the via property.

ParentAnimation is typically used within a Transition in conjunction with a ParentChange. When used in this manner, it animates any ParentChange that has occurred during the state change. This can be overridden by setting a specific target item using the target property.

See also Animation and Transitions in Qt Quick and Qt Quick Examples - Animation.

Property Documentation

The item to reparent.

When used in a transition, if no target is specified, all ParentChange occurrences are animated by the ParentAnimation.

The item to reparent via. This provides a way to do an unclipped animation when both the old parent and new parent are clipped.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.