Congratulations to our 2022 Qt Champions!

Rotate Animation

  • I want to make a rotate animation with QPropertyAnimation but i don't know how to do it, can someone help me to do it?

  • @Anh-Phan Hi! What is it you want to rotate?

  • @Wieland i want to rotate a pushbutton or qlabel, can you help me?

  • I think the easiest way to achieve this is to implement a custom QGraphicsEffect for rotation. You can then apply this to whatever widget you like and you can animate the rotation with QPropertyAnimation.

  • BTW: If you need a fancy interface use QtQuick. It makes such things much easier:

    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4
    Window {
        visible: true
        Button {
            id: btn
            anchors.centerIn: parent
            text: "Exit"
            onClicked: Qt.quit()
            transform: Rotation {
                origin.x: btn.width/2.0; origin.y: btn.height/2.0; angle: 0
                SequentialAnimation on angle {
                    loops: Animation.Infinite
                    PropertyAnimation { to: 360; duration: 1000 }
                    PropertyAnimation { to: 0; duration: 2000 }

Log in to reply