Qt World Summit: Register Today!

Why QML Animation does not support setDirection like QAbstractAnimation

  • I want an object, need it to fellow a complex path and move as an animation. The path is included line and curve. just like a train.

    Two solution: 1. PathAnimation or 2. states with multi-animation

    Problem of solution 1: The train maybe stop at a random time-point(pause the animation), and go reverse back to the start position(play animation reversely like QAbstractAnimation ), or continue to the end point.

    So i want know any way to play PathAnimation reversely?

  • Hi! If you need more control over the animation, you can use PathInterpolator:


    import QtQuick 2.7
    import QtQuick.Controls 2.0
    ApplicationWindow {
        visible: true
        width: 400
        height: 450
        title: "Fun with paths"
        color: "darkgrey"
        PathInterpolator {
            id: motionPath
            path: Path {
                PathCubic {
                    x: 350
                    y: 350
                    control1X: 350
                    control1Y: 0
                    control2X: 0
                    control2Y: 350
            progress: slider.position
        Rectangle {
            width: 50
            height: 50
            color: "orange"
            border.width: 3
            border.color: "black"
            x: motionPath.x
            y: motionPath.y
            rotation: motionPath.angle
            antialiasing: true
            Text {
                anchors.centerIn: parent
                text: Math.round(motionPath.progress*100) + " %"
        Slider {
            id: slider
            anchors.bottom: parent.bottom
            width: parent.width

Log in to reply