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. I want to pause my animation on button click:
QtWS25 Last Chance

I want to pause my animation on button click:

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 3 Posters 6.2k Views
  • 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
    DanSiddiqui
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      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
      0
      • D Offline
        D Offline
        DanSiddiqui
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          @
          ...
          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
          0
          • D Offline
            D Offline
            DanSiddiqui
            wrote on last edited by
            #5

            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
            0
            • T Offline
              T Offline
              task_struct
              wrote on last edited by
              #6

              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
              0
              • D Offline
                D Offline
                DanSiddiqui
                wrote on last edited by
                #7

                not working task_struct :(

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  task_struct
                  wrote on last edited by
                  #8

                  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
                  0
                  • D Offline
                    D Offline
                    DanSiddiqui
                    wrote on last edited by
                    #9

                    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
                    0
                    • T Offline
                      T Offline
                      task_struct
                      wrote on last edited by
                      #10

                      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
                      0
                      • D Offline
                        D Offline
                        DanSiddiqui
                        wrote on last edited by
                        #11

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

                        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