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. NumberAnimation on multiple properties at once

NumberAnimation on multiple properties at once

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 752 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.
  • S Offline
    S Offline
    shokarta
    wrote on last edited by
    #1

    hello guys,

    so I have:

    property bool transformation: false
    
    Rectangle {
        id: myRect
        x: 50; y:50
        color: "red"
    
        transform: Translate {
            x: transformation ? 25 : 0
            y: transformation ? 25 : 0
        }
        scale: transformation ? 3 : 0
        rotation: transformation ? 90 : 0
    
        Behaviour on rotation {
            NumberAnimation { duration: 500 }
        }
    }
    

    so when transformation turns to "true", then Rectangle changes position, scales and rotates, when lateron it turns back to false, all is reseted to initial state... works perfect...

    I also have set the NumberAnimation on rotation which also works perfect... but I would like to have all three transformations (transform, scale, rotate) doiung this animation at the same time...
    so at the same time i would see rectangle is moving to new direction, while its scaling and while its rotation...

    can this be done?

    johngodJ 1 Reply Last reply
    0
    • johngodJ johngod

      @shokarta There you go:

      import QtQuick
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
      
          property bool transformation: false
      
          property real finalX: transformation ?  250 : 50
          property real finalY: transformation ?  250 : 50
          property real finalScale: transformation ?  5 : 1
          property real finalRotation: transformation ?  360 : 0
      
          Rectangle {
              id: myRect
              width: 30
              height: 30
              x: 50; y:50
              color: "red"
      
              ParallelAnimation {
                  id: anim
                  NumberAnimation { target: myRect; property: "x"; to: finalX; duration: 1000 }
                  NumberAnimation { target: myRect; property: "y"; to: finalY; duration: 1000 }
                  NumberAnimation { target: myRect; property: "scale"; to: finalScale; duration: 1000 }
                  NumberAnimation { target: myRect; property: "rotation"; to: finalRotation; duration: 1000 }
              }
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
      
                  transformation = !transformation
                  anim.start()
      
              }
          }
      }
      
      S Offline
      S Offline
      shokarta
      wrote on last edited by
      #5

      @johngod
      unfortunatelly i have to use transform: Translate {}, i can not change directly x/y of Window{}.

      but at the end (this was tough to figure out) i did use this logic (definitely not nice and clean, but works):

      property bool transformation: false
      
      Rectangle {
          id: myRect
          x: 50; y:50
          color: "red"
      
      	property bool ownTrans: transformation
      	onOwnTransChanged: {
      		// scale
      		animationScale.from = ownTrans ? 1 : 3;
      		animationScale.to = ownTrans ? 3 : 1;
      
      		// rotation
      		animationRotation.from = ownTrans ? 0 : 90;
      		animationRotation.to = ownTrans ? 90 : 0;
      
      		// translate
      		animationTransformX.from = ownTrans ? 0 : myTranslate.x;
      		myTranslate.x = ownTrans ? 25 : 0;
      		animationTransformX.to = ownTrans ? myTranslate.x : 0;
      
      		animationTransformY.from = ownTrans ? 0 : myTranslate.y;
      		myTranslate.y = ownTrans ? 25 : 0;
      		animationTransformY.to = ownTrans ? myTranslate.y : 0;
      
      		// run animation
      		myParallelAnimation.start();
      	}
      
      	transform: Translate {
      		id: myTranslate
      		x: 0; y : 0
      	}
      
      	ParallelAnimation {
      		id: myParallelAnimation
      		property int dur: 100
      		running: false
      		NumberAnimation { id: animationTransformX;	target: myTranslate;	property: "x";			duration: myParallelAnimation.dur }
      		NumberAnimation { id: animationTransformY;	target: myTranslate;	property: "y";			duration: myParallelAnimation.dur }
      		NumberAnimation { id: animationScale;		target: objRoot;		property: "scale";		duration: myParallelAnimation.dur }
      		NumberAnimation { id: animationRotation;	target: objRoot;		property: "rotation";	duration: myParallelAnimation.dur }
      	}
      }
      
      GrecKoG 1 Reply Last reply
      0
      • S shokarta

        hello guys,

        so I have:

        property bool transformation: false
        
        Rectangle {
            id: myRect
            x: 50; y:50
            color: "red"
        
            transform: Translate {
                x: transformation ? 25 : 0
                y: transformation ? 25 : 0
            }
            scale: transformation ? 3 : 0
            rotation: transformation ? 90 : 0
        
            Behaviour on rotation {
                NumberAnimation { duration: 500 }
            }
        }
        

        so when transformation turns to "true", then Rectangle changes position, scales and rotates, when lateron it turns back to false, all is reseted to initial state... works perfect...

        I also have set the NumberAnimation on rotation which also works perfect... but I would like to have all three transformations (transform, scale, rotate) doiung this animation at the same time...
        so at the same time i would see rectangle is moving to new direction, while its scaling and while its rotation...

        can this be done?

        johngodJ Offline
        johngodJ Offline
        johngod
        wrote on last edited by
        #2

        @shokarta Yes it can, check ParallelAnimation https://doc.qt.io/qt-6/qml-qtquick-parallelanimation.html

        S 1 Reply Last reply
        1
        • johngodJ johngod

          @shokarta Yes it can, check ParallelAnimation https://doc.qt.io/qt-6/qml-qtquick-parallelanimation.html

          S Offline
          S Offline
          shokarta
          wrote on last edited by
          #3

          @johngod said in NumberAnimation on multiple properties at once:

          @shokarta Yes it can, check ParallelAnimation https://doc.qt.io/qt-6/qml-qtquick-parallelanimation.html

          Thank you, this is as far as I have figured out...
          unfortunately, I dont know realy how to use it combined... :(

          johngodJ 1 Reply Last reply
          0
          • S shokarta

            @johngod said in NumberAnimation on multiple properties at once:

            @shokarta Yes it can, check ParallelAnimation https://doc.qt.io/qt-6/qml-qtquick-parallelanimation.html

            Thank you, this is as far as I have figured out...
            unfortunately, I dont know realy how to use it combined... :(

            johngodJ Offline
            johngodJ Offline
            johngod
            wrote on last edited by
            #4

            @shokarta There you go:

            import QtQuick
            
            Window {
                width: 640
                height: 480
                visible: true
                title: qsTr("Hello World")
            
            
                property bool transformation: false
            
                property real finalX: transformation ?  250 : 50
                property real finalY: transformation ?  250 : 50
                property real finalScale: transformation ?  5 : 1
                property real finalRotation: transformation ?  360 : 0
            
                Rectangle {
                    id: myRect
                    width: 30
                    height: 30
                    x: 50; y:50
                    color: "red"
            
                    ParallelAnimation {
                        id: anim
                        NumberAnimation { target: myRect; property: "x"; to: finalX; duration: 1000 }
                        NumberAnimation { target: myRect; property: "y"; to: finalY; duration: 1000 }
                        NumberAnimation { target: myRect; property: "scale"; to: finalScale; duration: 1000 }
                        NumberAnimation { target: myRect; property: "rotation"; to: finalRotation; duration: 1000 }
                    }
                }
            
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
            
                        transformation = !transformation
                        anim.start()
            
                    }
                }
            }
            
            S 1 Reply Last reply
            1
            • johngodJ johngod

              @shokarta There you go:

              import QtQuick
              
              Window {
                  width: 640
                  height: 480
                  visible: true
                  title: qsTr("Hello World")
              
              
                  property bool transformation: false
              
                  property real finalX: transformation ?  250 : 50
                  property real finalY: transformation ?  250 : 50
                  property real finalScale: transformation ?  5 : 1
                  property real finalRotation: transformation ?  360 : 0
              
                  Rectangle {
                      id: myRect
                      width: 30
                      height: 30
                      x: 50; y:50
                      color: "red"
              
                      ParallelAnimation {
                          id: anim
                          NumberAnimation { target: myRect; property: "x"; to: finalX; duration: 1000 }
                          NumberAnimation { target: myRect; property: "y"; to: finalY; duration: 1000 }
                          NumberAnimation { target: myRect; property: "scale"; to: finalScale; duration: 1000 }
                          NumberAnimation { target: myRect; property: "rotation"; to: finalRotation; duration: 1000 }
                      }
                  }
              
                  MouseArea {
                      anchors.fill: parent
                      onClicked: {
              
                          transformation = !transformation
                          anim.start()
              
                      }
                  }
              }
              
              S Offline
              S Offline
              shokarta
              wrote on last edited by
              #5

              @johngod
              unfortunatelly i have to use transform: Translate {}, i can not change directly x/y of Window{}.

              but at the end (this was tough to figure out) i did use this logic (definitely not nice and clean, but works):

              property bool transformation: false
              
              Rectangle {
                  id: myRect
                  x: 50; y:50
                  color: "red"
              
              	property bool ownTrans: transformation
              	onOwnTransChanged: {
              		// scale
              		animationScale.from = ownTrans ? 1 : 3;
              		animationScale.to = ownTrans ? 3 : 1;
              
              		// rotation
              		animationRotation.from = ownTrans ? 0 : 90;
              		animationRotation.to = ownTrans ? 90 : 0;
              
              		// translate
              		animationTransformX.from = ownTrans ? 0 : myTranslate.x;
              		myTranslate.x = ownTrans ? 25 : 0;
              		animationTransformX.to = ownTrans ? myTranslate.x : 0;
              
              		animationTransformY.from = ownTrans ? 0 : myTranslate.y;
              		myTranslate.y = ownTrans ? 25 : 0;
              		animationTransformY.to = ownTrans ? myTranslate.y : 0;
              
              		// run animation
              		myParallelAnimation.start();
              	}
              
              	transform: Translate {
              		id: myTranslate
              		x: 0; y : 0
              	}
              
              	ParallelAnimation {
              		id: myParallelAnimation
              		property int dur: 100
              		running: false
              		NumberAnimation { id: animationTransformX;	target: myTranslate;	property: "x";			duration: myParallelAnimation.dur }
              		NumberAnimation { id: animationTransformY;	target: myTranslate;	property: "y";			duration: myParallelAnimation.dur }
              		NumberAnimation { id: animationScale;		target: objRoot;		property: "scale";		duration: myParallelAnimation.dur }
              		NumberAnimation { id: animationRotation;	target: objRoot;		property: "rotation";	duration: myParallelAnimation.dur }
              	}
              }
              
              GrecKoG 1 Reply Last reply
              0
              • S shokarta has marked this topic as solved on
              • S shokarta

                @johngod
                unfortunatelly i have to use transform: Translate {}, i can not change directly x/y of Window{}.

                but at the end (this was tough to figure out) i did use this logic (definitely not nice and clean, but works):

                property bool transformation: false
                
                Rectangle {
                    id: myRect
                    x: 50; y:50
                    color: "red"
                
                	property bool ownTrans: transformation
                	onOwnTransChanged: {
                		// scale
                		animationScale.from = ownTrans ? 1 : 3;
                		animationScale.to = ownTrans ? 3 : 1;
                
                		// rotation
                		animationRotation.from = ownTrans ? 0 : 90;
                		animationRotation.to = ownTrans ? 90 : 0;
                
                		// translate
                		animationTransformX.from = ownTrans ? 0 : myTranslate.x;
                		myTranslate.x = ownTrans ? 25 : 0;
                		animationTransformX.to = ownTrans ? myTranslate.x : 0;
                
                		animationTransformY.from = ownTrans ? 0 : myTranslate.y;
                		myTranslate.y = ownTrans ? 25 : 0;
                		animationTransformY.to = ownTrans ? myTranslate.y : 0;
                
                		// run animation
                		myParallelAnimation.start();
                	}
                
                	transform: Translate {
                		id: myTranslate
                		x: 0; y : 0
                	}
                
                	ParallelAnimation {
                		id: myParallelAnimation
                		property int dur: 100
                		running: false
                		NumberAnimation { id: animationTransformX;	target: myTranslate;	property: "x";			duration: myParallelAnimation.dur }
                		NumberAnimation { id: animationTransformY;	target: myTranslate;	property: "y";			duration: myParallelAnimation.dur }
                		NumberAnimation { id: animationScale;		target: objRoot;		property: "scale";		duration: myParallelAnimation.dur }
                		NumberAnimation { id: animationRotation;	target: objRoot;		property: "rotation";	duration: myParallelAnimation.dur }
                	}
                }
                
                GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #6

                @shokarta I would add another property solely for the animation and use it for the transformations:

                property bool transformation: false
                
                Rectangle {
                    id: myRect
                    x: 50; y:50
                    color: "red"
                    
                    property real transformationProgress: transformation ? 1 : 0
                    Behaviour on transformationProgress {
                        NumberAnimation { duration: 500 }
                    }
                
                    transform: Translate {
                        x: 25 * transformationProgress
                        y: 25 * transformationProgress
                    }
                    scale: 3 * transformationProgress
                    rotation: 90 * transformationProgress
                
                }
                
                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