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. Restart Animation inside OnStopped event
Forum Updated to NodeBB v4.3 + New Features

Restart Animation inside OnStopped event

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 903 Views 2 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    What about this code?

    SequentialAnimation {
            id: anim
            PropertyAction { target: rotSpin; property: "origin.x"; value: xCenterNeedle }
            PropertyAction { target: rotSpin; property: "origin.y"; value: yCenterNeedle }
            NumberAnimation { id: numAnim; target: rotSpin; property: "angle"; easing.type: Easing.Linear; to: _degree; duration: _time; }
    
            onStopped: {
                _degree = 123
                _time = 234
                anim.loops = 1;
                anim.start();
                return null;
            }
        }
    

    Is this allowed and safe?

    M 1 Reply Last reply
    0
    • M Mark81

      What about this code?

      SequentialAnimation {
              id: anim
              PropertyAction { target: rotSpin; property: "origin.x"; value: xCenterNeedle }
              PropertyAction { target: rotSpin; property: "origin.y"; value: yCenterNeedle }
              NumberAnimation { id: numAnim; target: rotSpin; property: "angle"; easing.type: Easing.Linear; to: _degree; duration: _time; }
      
              onStopped: {
                  _degree = 123
                  _time = 234
                  anim.loops = 1;
                  anim.start();
                  return null;
              }
          }
      

      Is this allowed and safe?

      M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      @Mark81

      Hi

      Why do you wanna restart animation with OnStopped event?

      Looks like you are looking for an infinite animation?

      If this is your case , there is a loops property in Animation

      If set to Animation.Infinite, the animation will continuously repeat until it is explicitly stopped - either by setting the running property to false, or by calling the stop() method.

      In your case you will have just to add loops after id: anim

      id: anim
      loops: Animation.Infinite
      

      ?

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        Yes, I'm already using that. Here I explained the reason of my request:

        https://forum.qt.io/topic/85693/change-numberanimation-while-running

        basically, I need to reach a specific angle when an event fires. Using Animation.Infinite, it seems I cannot retargetting the Animation properties. Hence my workaround was to stop the animation, in the onStopped event calculate how much it needs to go further and restart the animation with the new target and loops = 1.

        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