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. How to add multi-stage transition when Flipable transform??
Forum Updated to NodeBB v4.3 + New Features

How to add multi-stage transition when Flipable transform??

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 3 Posters 449 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.
  • K Offline
    K Offline
    Kamichanw
    wrote on 13 Jul 2023, 11:56 last edited by
    #1

    I'm trying to implement a Flipable that is not only able to rotate but also adjust its scale at the same time. More specifically, I want the scale of Flipable(or its front and back) can change from 1 to 0.5 and back from 0.5 to 1 smoothly. I mean, I need a NumerAnimation here.

    Here is code

    import QtQuick 2.0
    import QtQuick.Controls
    
    Window {
        id: control
        width: 360
        height: 320
        visible: true
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            onClicked: flipable.flipped = !flipable.flipped
        }
    
        Flipable {
            property bool flipped: false
            id: flipable
            anchors.fill: parent
            front: Rectangle {
                anchors.fill: parent
                color: "blue"
            }
            back: Rectangle {
                anchors.fill: parent
                color: "green"
            }
    
            transform: Rotation {
                id: rotation
                origin.x: flipable.width / 2
                origin.y: flipable.height / 2
                axis.x: 0
                axis.y: 1
                axis.z: 0
                angle: 0
            }
    
            states: State {
                PropertyChanges {
                    target: rotation
                    angle: 180
                }
                when: flipable.flipped
            }
    
            transitions: Transition {
                NumberAnimation {
                    target: rotation
                    property: "angle"
                    duration: 1000
                }
            }
        }
    }
    
    

    According to Qt doc, I cannot apply more than one transform at the same time, which means that it's impossible to append Scale to transform of Flipable.
    Therefore I think I could add a SequentialAnimation that change scale from 1 to 0.5 then back to 1 to Transition, but that is a multi-stage transiton, I don't know how to do.

    D 1 Reply Last reply 13 Jul 2023, 15:07
    0
    • K Offline
      K Offline
      Kamichanw
      wrote on 13 Jul 2023, 12:02 last edited by
      #2

      I also wrote a SequentialAnimation and started it on side changed.

      SequentialAnimation {
              id: scaleAnim
              NumberAnimation {
                  target: flipable
                  property: "scale"
                  duration: rotation.duration / 2
                  from: 1.0
                  to: 0.5
              }
              NumberAnimation {
                  target: flipable
                  property: "scale"
                  duration: rotation.duration / 2
                  from: 0.5
                  to: 1.0
              }
          }
      
          Flipable {
              property bool flipped: false
              onSideChanged: scaleAnim.start()
      ...
      

      However, it doesn't work at all.

      M 1 Reply Last reply 13 Jul 2023, 14:16
      0
      • K Kamichanw
        13 Jul 2023, 12:02

        I also wrote a SequentialAnimation and started it on side changed.

        SequentialAnimation {
                id: scaleAnim
                NumberAnimation {
                    target: flipable
                    property: "scale"
                    duration: rotation.duration / 2
                    from: 1.0
                    to: 0.5
                }
                NumberAnimation {
                    target: flipable
                    property: "scale"
                    duration: rotation.duration / 2
                    from: 0.5
                    to: 1.0
                }
            }
        
            Flipable {
                property bool flipped: false
                onSideChanged: scaleAnim.start()
        ...
        

        However, it doesn't work at all.

        M Offline
        M Offline
        Markkyboy
        wrote on 13 Jul 2023, 14:16 last edited by Markkyboy
        #3
        Flipable {
            id: flipable
        
            property bool flipped: false
        
            anchors.centerIn: parent
            front: Rectangle {
                id: front
                width: 500
                height: width
                color: "blue"
            }
            back: Rectangle {
                id: back
                width: 500
                height: width
                color: "green"
            }
            transform: Rotation {
                id: rotation
                origin.x: origin.y
                origin.y: flipable.width / 2
                axis.x: 0; axis.y: 1; axis.z: 0; angle: 0
            }
            states: State {
                PropertyChanges {
                    target: rotation
                    angle: 180
                }
                when: flipable.flipped
            }
            transitions: Transition {
                NumberAnimation {
                    target: rotation
                    property: "angle"
                    duration: 1000
                }
            }
            SequentialAnimation {
                id: scaleAnim
                PropertyAnimation {
                    targets: [front, back]
                    properties: "scale"
                    duration: 500
                    from: 1.0
                    to: 0.25
                }
                PropertyAnimation {
                    targets: [front, back]
                    properties: "scale"
                    duration: 500
                    from: 0.25
                    to: 1.0
                }
            }
        }
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            onClicked: {
                flipable.flipped = !flipable.flipped
                scaleAnim.running = true
                console.log(scaleAnim.running)
            }
        }
        

        }

        Don't just sit there standing around, pick up a shovel and sweep up!

        I live by the sea, not in it.

        K 1 Reply Last reply 13 Jul 2023, 14:37
        0
        • M Markkyboy
          13 Jul 2023, 14:16
          Flipable {
              id: flipable
          
              property bool flipped: false
          
              anchors.centerIn: parent
              front: Rectangle {
                  id: front
                  width: 500
                  height: width
                  color: "blue"
              }
              back: Rectangle {
                  id: back
                  width: 500
                  height: width
                  color: "green"
              }
              transform: Rotation {
                  id: rotation
                  origin.x: origin.y
                  origin.y: flipable.width / 2
                  axis.x: 0; axis.y: 1; axis.z: 0; angle: 0
              }
              states: State {
                  PropertyChanges {
                      target: rotation
                      angle: 180
                  }
                  when: flipable.flipped
              }
              transitions: Transition {
                  NumberAnimation {
                      target: rotation
                      property: "angle"
                      duration: 1000
                  }
              }
              SequentialAnimation {
                  id: scaleAnim
                  PropertyAnimation {
                      targets: [front, back]
                      properties: "scale"
                      duration: 500
                      from: 1.0
                      to: 0.25
                  }
                  PropertyAnimation {
                      targets: [front, back]
                      properties: "scale"
                      duration: 500
                      from: 0.25
                      to: 1.0
                  }
              }
          }
          MouseArea {
              anchors.fill: parent
              hoverEnabled: true
              onClicked: {
                  flipable.flipped = !flipable.flipped
                  scaleAnim.running = true
                  console.log(scaleAnim.running)
              }
          }
          

          }

          K Offline
          K Offline
          Kamichanw
          wrote on 13 Jul 2023, 14:37 last edited by Kamichanw
          #4

          @Markkyboy Thanks for your answer, but it doesn't work well. As you can see,

          f1ea92fe-7380-46cc-9e8f-6e3a4ef52265-image.png

          The rectange is moved to the right bottom corner. When I clicked the window, it rotated weirdly and became like this

          58646d1b-a0ca-42fa-90bb-4dc3fa0372d2-image.png

          M 1 Reply Last reply 13 Jul 2023, 14:52
          0
          • K Kamichanw
            13 Jul 2023, 14:37

            @Markkyboy Thanks for your answer, but it doesn't work well. As you can see,

            f1ea92fe-7380-46cc-9e8f-6e3a4ef52265-image.png

            The rectange is moved to the right bottom corner. When I clicked the window, it rotated weirdly and became like this

            58646d1b-a0ca-42fa-90bb-4dc3fa0372d2-image.png

            M Offline
            M Offline
            Markkyboy
            wrote on 13 Jul 2023, 14:52 last edited by
            #5

            @Kamichanw - you may need to play around with the format of the flipable module, perhaps disable a few lines here and there.....with tinkering you should get what you need/want.

            It worked for me, which is why I posted my code.

            My code was originally nested in a page as I am using Sailfish SDK to create QML apps on my Sony Xperia, so I am able to quickly slap a working app together and briefly test it.

            Don't just sit there standing around, pick up a shovel and sweep up!

            I live by the sea, not in it.

            1 Reply Last reply
            0
            • K Kamichanw
              13 Jul 2023, 11:56

              I'm trying to implement a Flipable that is not only able to rotate but also adjust its scale at the same time. More specifically, I want the scale of Flipable(or its front and back) can change from 1 to 0.5 and back from 0.5 to 1 smoothly. I mean, I need a NumerAnimation here.

              Here is code

              import QtQuick 2.0
              import QtQuick.Controls
              
              Window {
                  id: control
                  width: 360
                  height: 320
                  visible: true
                  MouseArea {
                      anchors.fill: parent
                      hoverEnabled: true
                      onClicked: flipable.flipped = !flipable.flipped
                  }
              
                  Flipable {
                      property bool flipped: false
                      id: flipable
                      anchors.fill: parent
                      front: Rectangle {
                          anchors.fill: parent
                          color: "blue"
                      }
                      back: Rectangle {
                          anchors.fill: parent
                          color: "green"
                      }
              
                      transform: Rotation {
                          id: rotation
                          origin.x: flipable.width / 2
                          origin.y: flipable.height / 2
                          axis.x: 0
                          axis.y: 1
                          axis.z: 0
                          angle: 0
                      }
              
                      states: State {
                          PropertyChanges {
                              target: rotation
                              angle: 180
                          }
                          when: flipable.flipped
                      }
              
                      transitions: Transition {
                          NumberAnimation {
                              target: rotation
                              property: "angle"
                              duration: 1000
                          }
                      }
                  }
              }
              
              

              According to Qt doc, I cannot apply more than one transform at the same time, which means that it's impossible to append Scale to transform of Flipable.
              Therefore I think I could add a SequentialAnimation that change scale from 1 to 0.5 then back to 1 to Transition, but that is a multi-stage transiton, I don't know how to do.

              D Offline
              D Offline
              Danima
              wrote on 13 Jul 2023, 15:07 last edited by Danima
              #6

              @Kamichanw

              import QtQuick 2.0
              import QtQuick.Controls 2.0
              import QtQuick.Window 2.2
              
              Window {
                  id: control
                  width: 360
                  height: 320
                  visible: true
                  MouseArea {
                      anchors.fill: parent
                      hoverEnabled: true
                      onClicked: flipable.flipped = !flipable.flipped
                  }
              
                  Flipable {
                      property bool flipped: false
                      id: flipable
                      anchors.fill: parent
                      front: Rectangle {
                          anchors.fill: parent
                          color: "blue"
                      }
                      back: Rectangle {
                          anchors.fill: parent
                          color: "green"
                      }
              
                      transform: [
                          Rotation {
                          id: rotation
                          origin.x: flipable.width / 2
                          origin.y: flipable.height / 2
                          axis.x: 0
                          axis.y: 1
                          axis.z: 0
                          angle: 0
                      }
                        ,
                       Scale {id: scale; origin.x: flipable.width / 2; origin.y: flipable.height / 2; xScale: 1;yScale: 1}
                      ]
              
                      states: State {
                          PropertyChanges {
                              target: rotation
                              angle: 180
                          }
                          PropertyChanges {
                              target: scale
                              xScale: 0.5
                              yScale:0.5
                          }
                          when: flipable.flipped
                      }
              
                      transitions: Transition {
                          NumberAnimation {
                              target: rotation
                              property: "angle"
                              duration: 1000
                          }
                          NumberAnimation {
                              target: scale
                              properties: "xScale,yScale"
                              duration: 1000
                          }
                      }
                  }
              }
              
              
              K 1 Reply Last reply 13 Jul 2023, 15:14
              0
              • D Danima
                13 Jul 2023, 15:07

                @Kamichanw

                import QtQuick 2.0
                import QtQuick.Controls 2.0
                import QtQuick.Window 2.2
                
                Window {
                    id: control
                    width: 360
                    height: 320
                    visible: true
                    MouseArea {
                        anchors.fill: parent
                        hoverEnabled: true
                        onClicked: flipable.flipped = !flipable.flipped
                    }
                
                    Flipable {
                        property bool flipped: false
                        id: flipable
                        anchors.fill: parent
                        front: Rectangle {
                            anchors.fill: parent
                            color: "blue"
                        }
                        back: Rectangle {
                            anchors.fill: parent
                            color: "green"
                        }
                
                        transform: [
                            Rotation {
                            id: rotation
                            origin.x: flipable.width / 2
                            origin.y: flipable.height / 2
                            axis.x: 0
                            axis.y: 1
                            axis.z: 0
                            angle: 0
                        }
                          ,
                         Scale {id: scale; origin.x: flipable.width / 2; origin.y: flipable.height / 2; xScale: 1;yScale: 1}
                        ]
                
                        states: State {
                            PropertyChanges {
                                target: rotation
                                angle: 180
                            }
                            PropertyChanges {
                                target: scale
                                xScale: 0.5
                                yScale:0.5
                            }
                            when: flipable.flipped
                        }
                
                        transitions: Transition {
                            NumberAnimation {
                                target: rotation
                                property: "angle"
                                duration: 1000
                            }
                            NumberAnimation {
                                target: scale
                                properties: "xScale,yScale"
                                duration: 1000
                            }
                        }
                    }
                }
                
                
                K Offline
                K Offline
                Kamichanw
                wrote on 13 Jul 2023, 15:14 last edited by
                #7

                @Danima Nice try, but it doesn't work as well. After rotation, xScale kept 0.5 instead of 1. In my case, I want xScale revert to 1 after transformation.

                D 1 Reply Last reply 13 Jul 2023, 15:29
                0
                • K Kamichanw
                  13 Jul 2023, 15:14

                  @Danima Nice try, but it doesn't work as well. After rotation, xScale kept 0.5 instead of 1. In my case, I want xScale revert to 1 after transformation.

                  D Offline
                  D Offline
                  Danima
                  wrote on 13 Jul 2023, 15:29 last edited by
                  #8

                  @Kamichanw

                  import QtQuick 2.0
                  import QtQuick.Controls 2.0
                  import QtQuick.Window 2.2
                  
                  Window {
                      id: control
                      width: 360
                      height: 320
                      visible: true
                      MouseArea {
                          anchors.fill: parent
                          hoverEnabled: true
                          onClicked: flipable.flipped = !flipable.flipped
                      }
                  
                      Flipable {
                          property bool flipped: false
                          id: flipable
                          anchors.fill: parent
                          front: Rectangle {
                              anchors.fill: parent
                              color: "blue"
                          }
                          back: Rectangle {
                              anchors.fill: parent
                              color: "green"
                          }
                  
                          transform:
                              Rotation {
                              id: rotation
                              origin.x: flipable.width / 2
                              origin.y: flipable.height / 2
                              axis.x: 0
                              axis.y: 1
                              axis.z: 0
                              angle: 0
                          }
                  
                  
                          states: State {
                              PropertyChanges {
                                  target: rotation
                                  angle: 180
                              }
                  
                              when: flipable.flipped
                          }
                  
                          transitions: Transition {
                              SequentialAnimation {
                                  ParallelAnimation
                                  {
                                      NumberAnimation {
                                          target: rotation
                                          property: "angle"
                                          duration: 1000
                                      }
                                      NumberAnimation {
                                          target:flipable
                                          property: "scale"
                                          from:1
                                          to:0.5
                                          duration: 1000
                                      }
                                  }
                                  NumberAnimation {
                                      target:flipable
                                      property: "scale"
                                      from:0.5
                                      to:1
                                      duration: 1000
                                  }
                              }
                          }
                      }
                  }
                  
                  
                  K 1 Reply Last reply 13 Jul 2023, 15:41
                  0
                  • D Danima
                    13 Jul 2023, 15:29

                    @Kamichanw

                    import QtQuick 2.0
                    import QtQuick.Controls 2.0
                    import QtQuick.Window 2.2
                    
                    Window {
                        id: control
                        width: 360
                        height: 320
                        visible: true
                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                            onClicked: flipable.flipped = !flipable.flipped
                        }
                    
                        Flipable {
                            property bool flipped: false
                            id: flipable
                            anchors.fill: parent
                            front: Rectangle {
                                anchors.fill: parent
                                color: "blue"
                            }
                            back: Rectangle {
                                anchors.fill: parent
                                color: "green"
                            }
                    
                            transform:
                                Rotation {
                                id: rotation
                                origin.x: flipable.width / 2
                                origin.y: flipable.height / 2
                                axis.x: 0
                                axis.y: 1
                                axis.z: 0
                                angle: 0
                            }
                    
                    
                            states: State {
                                PropertyChanges {
                                    target: rotation
                                    angle: 180
                                }
                    
                                when: flipable.flipped
                            }
                    
                            transitions: Transition {
                                SequentialAnimation {
                                    ParallelAnimation
                                    {
                                        NumberAnimation {
                                            target: rotation
                                            property: "angle"
                                            duration: 1000
                                        }
                                        NumberAnimation {
                                            target:flipable
                                            property: "scale"
                                            from:1
                                            to:0.5
                                            duration: 1000
                                        }
                                    }
                                    NumberAnimation {
                                        target:flipable
                                        property: "scale"
                                        from:0.5
                                        to:1
                                        duration: 1000
                                    }
                                }
                            }
                        }
                    }
                    
                    
                    K Offline
                    K Offline
                    Kamichanw
                    wrote on 13 Jul 2023, 15:41 last edited by
                    #9

                    @Danima This is close to what I desired. My goal is

                    transitions: Transition {
                                ParallelAnimation {
                                    NumberAnimation {
                                        target: rotation
                                        property: "angle"
                                        duration: 1000
                                    }
                                    SequentialAnimation {
                                        NumberAnimation {
                                            target: flipable
                                            property: "scale"
                                            from: 1
                                            to: 0.5
                                            duration: 500
                                        }
                                        NumberAnimation {
                                            target: flipable
                                            property: "scale"
                                            from: 0.5
                                            to: 1
                                            duration: 500
                                        }
                                    }
                                }
                            }
                    

                    I finally found out why my animation worked wrongly. rotation.duration is unaccessible, which makes me confused a lot. In fact, when I try to print it, it shows undefined. Is there anyone knows the reason?

                    D 1 Reply Last reply 13 Jul 2023, 15:49
                    0
                    • K Kamichanw
                      13 Jul 2023, 15:41

                      @Danima This is close to what I desired. My goal is

                      transitions: Transition {
                                  ParallelAnimation {
                                      NumberAnimation {
                                          target: rotation
                                          property: "angle"
                                          duration: 1000
                                      }
                                      SequentialAnimation {
                                          NumberAnimation {
                                              target: flipable
                                              property: "scale"
                                              from: 1
                                              to: 0.5
                                              duration: 500
                                          }
                                          NumberAnimation {
                                              target: flipable
                                              property: "scale"
                                              from: 0.5
                                              to: 1
                                              duration: 500
                                          }
                                      }
                                  }
                              }
                      

                      I finally found out why my animation worked wrongly. rotation.duration is unaccessible, which makes me confused a lot. In fact, when I try to print it, it shows undefined. Is there anyone knows the reason?

                      D Offline
                      D Offline
                      Danima
                      wrote on 13 Jul 2023, 15:49 last edited by
                      #10

                      @Kamichanw said in How to add multi-stage transition when Flipable transform??:

                      rotation

                      Rotation only define parameters of rotation not animation's duration.
                      https://doc.qt.io/qt-6/qml-qtquick-rotation.html

                      K 1 Reply Last reply 13 Jul 2023, 15:55
                      0
                      • D Danima
                        13 Jul 2023, 15:49

                        @Kamichanw said in How to add multi-stage transition when Flipable transform??:

                        rotation

                        Rotation only define parameters of rotation not animation's duration.
                        https://doc.qt.io/qt-6/qml-qtquick-rotation.html

                        K Offline
                        K Offline
                        Kamichanw
                        wrote on 13 Jul 2023, 15:55 last edited by
                        #11

                        @Danima OMG, I forgot that, so stupid...

                        1 Reply Last reply
                        0
                        • K Kamichanw has marked this topic as solved on 13 Jul 2023, 15:56

                        1/11

                        13 Jul 2023, 11:56

                        • Login

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