RotationAnimation: how to rotate about non-center coordinates?



  • I'm using RotationAnimation for the first time. This works fine. The image
    is 190 x 44 pixels and rotates about the center at x=95, y=22. I would like
    to have it rotate about 164, 22 instead. How can I do this with
    RotationAnimation? If it can't be done this way, what is the proper way to
    do it?

    RotationAnimation on rotation {
    from: 0
    to: 360
    duration: 3000
    direction: RotationAnimation.Clockwise
    loops: Animation.Infinite
    }



  • You can use QML Rotation.



  • Yes. I tried that and it works except that I don't know how to animate this solution.

    thanks,
    Bob



  • import QtQuick 2.6
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
    
        Rectangle {
            width: 190
            height: 44
            color: "red"
            anchors.centerIn: parent
    
            transform: Rotation {
                origin.x: 164
                origin.y: 22
    
                RotationAnimation on angle {
                    from: 0
                    to: 360
                    duration: 3000
                    direction: RotationAnimation.Clockwise
                    loops: Animation.Infinite
                }
            }
        }
    }


  • Yes. That's what I was looking for. Thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.