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. Reusable SequentialAnimation
Qt 6.11 is out! See what's new in the release blog

Reusable SequentialAnimation

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.1k 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.
  • J Offline
    J Offline
    jknick
    wrote on last edited by
    #1

    I'm trying to make a reusable animation and it's not working.
    Why would I not be able to do something like this?

    I'm defining an animation in file "ZoomAnim.qml" :

    @
    import QtQuick 2.1

    SequentialAnimation on scale {
    PropertyAnimation { property: "scale"; to: 2.0; duration: 500 }
    PropertyAnimation { property: "scale"; to: 1.0; duration: 500 }
    }
    @

    And in another file trying to do something like this:

    @
    Rectangle {
    id: rect
    ZoomAnim { id: myZoom }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            myZoom.running = true
        }
    }
    

    }
    @

    Which results in no animation. Presumably the PropertyAnimations are not getting good targets.

    Or is there another preferred way to reuse an animation like this across a collection of widgets?

    Thanks,
    Jake

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on last edited by
      #2

      Hi,

      example below should work,

      you have indeed to set proper targets,

      "on scale" works as a shortcut, and only inside the target, not from a different component.

      main.qml
      @
      import QtQuick 2.0

      Rectangle {
      width: 360
      height: 360

      ZoomAnimation { 
          id: myZoomAnimation
      
          myTarget: myRect 
      }
      
      Rectangle {
          id: myRect
      
          color: "red"
      
          width: 100
          height: 100
      
          anchors.centerIn: parent
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  myZoomAnimation.running = true;
              }
          }
      }
      

      }
      @

      ZoomAnimation.qml
      @
      import QtQuick 2.0

      SequentialAnimation {

      property variant myTarget;
      
      PropertyAnimation { 
          target: myTarget
          property: "scale"
          to: 2.0
          duration: 500 
      }
      PropertyAnimation { 
          target: myTarget
          property: "scale"
          to: 1.0
          duration: 500 
      }
      

      }
      @

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jknick
        wrote on last edited by
        #3

        And it's so obvious is retrospect.

        Thanks!

        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