Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How do I add a wait for an animation to be completed?



  • Hi,

    I have an animation for hiding a menu. I want that whenever I show a pop-up; the menu should hide and then the pop-up should be displayed.

    I am looking for a way to pause / wait for the animation to complete before I continue with the code.
    I am also quite new to QML, so most of its qualities escape me.
    The animation for the menu closing is called in multiple places. I am also pressed for performance, so adding a signal at the end and checking with a variable is something I want to avoid.

    Thanks


  • Moderators

    There are several ways to do this.

    First, you can add the code you want to execute later to onFinished slot in your animation:

    Animation {
      onFinished: console.log("Something")
    }
    

    Or you can use onRunningChanged if you prefer.

    Another possibility is to set up a sequential animation:

    SequentialAnimation {
      Animation {
        // This is your current animation
      }
      ScriptAction {
        script: console.log("I'm executed after animation ends")
      }
    }
    

Log in to reply