Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Mousearea: wait until animation is completed to call different state. [solved]
Qt 6.11 is out! See what's new in the release blog

Mousearea: wait until animation is completed to call different state. [solved]

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dstudentx
    wrote on last edited by
    #1

    I have a image when the user clicks on it the image is rotated 180 degrees than after that a new state is called.
    my problem is when the image is clicked the state is called right after the animated is fired so the animation is never shown because the new state is fired.

    Is there a pause() or wait() function I can call? or maybe a wait until animation complete?

    @ Image {
    id: image6
    x: 59
    y: 33
    width: 100
    height: 100
    source: "images/bmi-mm-movies.png"
    states: State {
    name: "rotated"
    PropertyChanges { target: image6; rotation: 180}
    }
    transitions: Transition {
    RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }
    }
    }@

    The mousearea

    @ MouseArea {
    id: movie_mouse_mm
    x: 392
    y: 364
    width: 104
    height: 100
    onClicked:{
    image6.state = "rotated"
    page.state = 'State1'
    Logic.get_db(5,0);
    }
    }@

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bjanuario
      wrote on last edited by
      #2

      Maybe you are looking into @Qt.WaitCursor@

      You can find more info here:
      "http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-mousearea.html":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-mousearea.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dstudentx
        wrote on last edited by
        #3

        Thanks for the help

        Can I just call 'State1' after the animation completes?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bjanuario
          wrote on last edited by
          #4

          Yes, I think the best way is to use signals and slots to connect and check this.

          Kind Regards

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JapieKrekel
            wrote on last edited by
            #5

            You can simply check for the onRunningChanged event in your animation like so:
            @
            transitions: Transition { RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise; onRunningChanged: {
            if (!running) page.state = "State1"
            }
            }
            }
            @
            Once the animation is done running will go back to false, checking for !running should do the trick.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dstudentx
              wrote on last edited by
              #6

              JapieKrekel:
              I wish that would work but onRunningChanged does not work if Animation is inside transition.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JapieKrekel
                wrote on last edited by
                #7

                You're right. My bad, usually I make a small example to test it, and you guessed it, this time I didn't...

                I made a small test and the onRunningChanged does work on on the Transition though.

                The example below shows the log at the beginning and end of the transition.

                @
                import QtQuick 2.0

                Rectangle {
                id : root
                width : 300
                height : 300

                MouseArea {
                    anchors.fill: parent
                    onClicked: icon.state = "rotated"
                }
                
                Rectangle {
                    id: icon
                    color: "red"
                    width: 50
                    height: 50
                    anchors.centerIn: parent
                    
                    states : [
                        State {
                            name: "rotated"
                            PropertyChanges {
                                target: icon
                                rotation: 360
                            }
                        }
                    ]
                    
                    transitions: Transition {
                        RotationAnimation {
                            properties: "rotation"
                            duration: 2000
                        }
                        onRunningChanged: console.log("rotation running: " + running)
                    }
                }
                

                }
                @

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dstudentx
                  wrote on last edited by
                  #8

                  You're the man JapieKrekel!
                  I just added
                  @
                  ...
                  onRunningChanged: if(!running) page.state = 'State1'
                  ...
                  @
                  and it worked!

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JapieKrekel
                    wrote on last edited by
                    #9

                    Glad to help. I learned from it too ;)

                    Don't forget to mark the topic [Solved]

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved