Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    I want to pause my animation on button click:

    QML and Qt Quick
    3
    11
    5461
    Loading More Posts
    • 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
      DanSiddiqui last edited by

      I am using following code i want to pause and resume button on this animation:
      @
      Rectangle {
      id: ball
      Image {
      id: img
      source: "images/ring1.png"
      }
      // Add a property for the target y coordinate
      property variant direction : "right"

              x: -100;  width: 0; height: 0; z: 1
              //color: "Lime"
      
              // Move the ball to the right and back to the left repeatedly
              SequentialAnimation on x {
              id:xani
              PauseAnimation { duration: 200 }
              running: false;
              loops: Animation.Infinite
              NumberAnimation { from:0;to: bubbleLevel.width - 40; duration: 3000 }
              ScriptAction {
                   script: {
                     }
                  }}
      
              Behavior on y {id:yani; SpringAnimation{ id:sab; velocity: 150; }
              }
      
      
              Component.onCompleted: {y = bubbleLevel.height-100;} // start the ball motion
      
              onYChanged: {
      
                  
                  if (y <= 80) {
                      y = bubbleLevel.height - 100;
      
                  }
                  if (y >= bubbleLevel.height - 130) {
                      y = 0;
      
                  }
                  
              }
          }
      

      @

      1 Reply Last reply Reply Quote 0
      • M
        mlong last edited by

        Using Qt components:

        @
        Button {
        text: xani.running?"Pause":"Resume"
        onClicked: { xani.running = !xani.running }
        }
        @

        (or something to that effect)

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply Reply Quote 0
        • D
          DanSiddiqui last edited by

          Thanks mlong it stop moving on x-axis but not on y-axis ,if i put as sab.pause(); for stop and sab.resume(); to move again but its not working. On click event my image is moving on top or on the bottom of the screen, but not paused plz tell me why it is moving on yaxis.

          1 Reply Last reply Reply Quote 0
          • M
            mlong last edited by

            @
            ...
            onClicked: {
            xani.running = !xani.running
            sab.running = !sab.running
            }
            @

            maybe?

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply Reply Quote 0
            • D
              DanSiddiqui last edited by

              it not pause my animation ,my (id:img) image moving on the bottom or top. i also want to resume animation where i paused.

              1 Reply Last reply Reply Quote 0
              • T
                task_struct last edited by

                I think xani.running = false is equal to xani.stop() Try with xani.paused property.

                @
                onClicked: {
                xani.paused = !xani.paused
                sab.paused = !sab.paused
                }
                @

                "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

                • Linu...
                1 Reply Last reply Reply Quote 0
                • D
                  DanSiddiqui last edited by

                  not working task_struct :(

                  1 Reply Last reply Reply Quote 0
                  • T
                    task_struct last edited by

                    May be I don't understaned you well, but this works:

                    @
                    import QtQuick 1.0

                    Rectangle {
                    id: bubbleLevel

                    width: 400
                    height: 400
                    
                    Rectangle {
                        id: animItem
                        width: 50
                        height: 50
                        color: "black"
                    
                        SequentialAnimation on x {
                            id: xani
                            loops: Animation.Infinite
                            NumberAnimation {
                                from: 10; to: 200
                                duration: 3000
                            }
                            NumberAnimation {
                                from: 200; to: 10
                                duration: 3000
                            }
                        }
                    }
                    
                    Rectangle {
                        id: button
                        width: 50
                        height: 30
                        color: "red"
                        anchors.right: parent.right
                        anchors.rightMargin: 5
                        anchors.bottom: parent.bottom
                        anchors.bottomMargin: 5
                        Text { text: "click" }
                    
                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                xani.paused = !xani.paused
                            }
                        }
                    }
                    

                    }
                    @

                    Is that what you're trying to achieve?

                    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

                    • Linu...
                    1 Reply Last reply Reply Quote 0
                    • D
                      DanSiddiqui last edited by

                      thanks , kindly add y component ,SpringAnimation, becuase m also want spring animation as a bouncing ball that spring animation not pausing.In the code below bubbleLevel is a background image having width, height as mobile's resolution (480*854).
                      @
                        Behavior on y {id:yani; SpringAnimation{ id:sab; velocity: 150; }
                                  }
                       
                       
                                  Component.onCompleted: {y = bubbleLevel.height-100;} // start the ball motion
                       
                                  onYChanged: {
                       
                                       
                                      if (y <= 80) {
                                          y = bubbleLevel.height - 100;
                       
                                      }
                                      if (y >= bubbleLevel.height - 130) {
                                          y = 0;
                       
                                      }
                                       
                                  }
                      @

                      1 Reply Last reply Reply Quote 0
                      • T
                        task_struct last edited by

                        Hello,

                        I've tried with Behavior animation and I receive this message:

                        @
                        QML SpringAnimation: setPaused() cannot be used on non-root animation nodes.
                        @

                        I've also tried with @yani.animation.paused = !yani.animation.paused@ but result is the same.
                        It seems that there is another animation that contains animations declared in Behavior but it is not accessible. :(

                        "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

                        • Linu...
                        1 Reply Last reply Reply Quote 0
                        • D
                          DanSiddiqui last edited by

                          yes i don't know why yani.paused or sab.paused is not working :(

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post