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

Animation

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

    Hi,

    Please read this note from this page:
    Now you can play around with the animation by changing the to and duration property or you could add another animation for example on the opacity or even the scale. Combining these it could look like the object is disappearing in the deep space. Try it out!

    I used OpacityAnimator and ScaleAnimator as below, using the Help button of Qt Creator. Is it what it asked, please?

    animation.qml:

    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Animation")
    
        Image {
            id: root
            source: "assets/background.png"
    
            property int padding: 40
            property int duration: 700
            property bool running: false
    
            Image {
                id: box
                x: root.padding
                y: (root.height-height)/2
                source: "assets/box_green.png"
            }
    
           NumberAnimation on x {
                    to: root.width
                    duration: root.duration
                    running: root.running
                }
    
           RotationAnimation on rotation {
                    to: 360
                    duration: root.duration
                    running: root.running
                }
    
           OpacityAnimator {
               target: root;
               from: 0;
               to: 1;
               duration: root.duration
               running: root.running
           }
    
           ScaleAnimator {
               target: root;
               from: 0.25;
               to: 1;
               duration: root.duration
               running: root.running
           }
         }
    
            MouseArea {
                anchors.fill: root
                onClicked: root.running = true
            }
    
        Button {
            id: quit
            x: 20; y: 400
            text: qsTr("Quit")
            onClicked: close()
        }
    }
    
    E 1 Reply Last reply
    0
    • tomyT tomy

      Hi,

      Please read this note from this page:
      Now you can play around with the animation by changing the to and duration property or you could add another animation for example on the opacity or even the scale. Combining these it could look like the object is disappearing in the deep space. Try it out!

      I used OpacityAnimator and ScaleAnimator as below, using the Help button of Qt Creator. Is it what it asked, please?

      animation.qml:

      import QtQuick 2.6
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Animation")
      
          Image {
              id: root
              source: "assets/background.png"
      
              property int padding: 40
              property int duration: 700
              property bool running: false
      
              Image {
                  id: box
                  x: root.padding
                  y: (root.height-height)/2
                  source: "assets/box_green.png"
              }
      
             NumberAnimation on x {
                      to: root.width
                      duration: root.duration
                      running: root.running
                  }
      
             RotationAnimation on rotation {
                      to: 360
                      duration: root.duration
                      running: root.running
                  }
      
             OpacityAnimator {
                 target: root;
                 from: 0;
                 to: 1;
                 duration: root.duration
                 running: root.running
             }
      
             ScaleAnimator {
                 target: root;
                 from: 0.25;
                 to: 1;
                 duration: root.duration
                 running: root.running
             }
           }
      
              MouseArea {
                  anchors.fill: root
                  onClicked: root.running = true
              }
      
          Button {
              id: quit
              x: 20; y: 400
              text: qsTr("Quit")
              onClicked: close()
          }
      }
      
      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @tomy If I would want to fullfill the purpose of the "exercise" as stated I would rather do

      OpacityAnimator {
                 target: root;
                 from: 1;
                 to: 0;
                 etc...
             }
      
             ScaleAnimator {
                 target: root;
                 from: 1;
                 to: 0.1;
                 etc...
            }
      

      Now it's "disappearing in" rather than "appering from".

      1 Reply Last reply
      1

      • Login

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