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 customize animation on show and close?

How to customize animation on show and close?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 480 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 last edited by
    #1

    In qt widget, I can override onShowEvent and onCloseEvent , but in qml, it might be tough. Here is my current solution:

    property bool closable: false
    Component.onCompleted: {
        showAnim.start()
     }
    
    NumberAnimation {
        id: showAnim
        target: rect
        properties: "opacity,scale"
        from: 0.75
        to: 1
        duration: 40
    }
    
    NumberAnimation {
        id: fadeAnim
        target: rect
        properties: "opacity,scale"
        duration: showAnim.duration
        onFinished: {
            closable = true
            close()
        }
        from: showAnim.to
        to: showAnim.from
    }
    onClosing: event => {
                   event.accepted = closable
                   if (!closable) {
                       fadeAnim.start()
                   }
               }
    

    Is there better way?

    L 1 Reply Last reply
    0
    • K Kamichanw

      In qt widget, I can override onShowEvent and onCloseEvent , but in qml, it might be tough. Here is my current solution:

      property bool closable: false
      Component.onCompleted: {
          showAnim.start()
       }
      
      NumberAnimation {
          id: showAnim
          target: rect
          properties: "opacity,scale"
          from: 0.75
          to: 1
          duration: 40
      }
      
      NumberAnimation {
          id: fadeAnim
          target: rect
          properties: "opacity,scale"
          duration: showAnim.duration
          onFinished: {
              closable = true
              close()
          }
          from: showAnim.to
          to: showAnim.from
      }
      onClosing: event => {
                     event.accepted = closable
                     if (!closable) {
                         fadeAnim.start()
                     }
                 }
      

      Is there better way?

      L Offline
      L Offline
      lemons
      wrote on last edited by
      #2

      @Kamichanw you can customize the enter and exit transitions:

      ApplicationWindow {
          width: 640
          height: 640
          visible: true
      
          Popup {
              id: animatedPopup
              parent: Overlay.overlay ? Overlay.overlay : Window.contentItem
              modal: true
              // using anchors can be tricky with scale animations
              x: (parent.width - width) / 2
              y: (parent.height - height) / 2
              height: 500
              width: 300
              padding: 0
      
              Text {
                  anchors.centerIn: parent
                  text: "Click outside to close"
              }
      
              background: Rectangle {
                  anchors.fill: parent
                  color: "#468055"
                  radius: 15
              }
      
              enter: Transition {
                  ParallelAnimation {
                      // animate opacity from 0 to 1 for a more continuous animation
                      NumberAnimation {
                          properties: "opacity"
                          from: 0
                          to: 1
                          duration: 64
                      }
                      NumberAnimation {
                          properties: "scale"
                          from: 0.75
                          to: 1
                          duration: 64
                      }
                  }
              }
              exit: Transition {
                  ParallelAnimation {
                      NumberAnimation {
                          properties: "opacity"
                          from: 1
                          to: 0
                          duration: 64
                      }
                      NumberAnimation {
                          properties: "scale"
                          from: 1
                          to: 0.75
                          duration: 64
                      }
                  }
              }
          }
          Button {
              anchors.centerIn: parent
              onClicked: animatedPopup.open()
              text: "Open"
          }
      }
      
      K 1 Reply Last reply
      0
      • L lemons

        @Kamichanw you can customize the enter and exit transitions:

        ApplicationWindow {
            width: 640
            height: 640
            visible: true
        
            Popup {
                id: animatedPopup
                parent: Overlay.overlay ? Overlay.overlay : Window.contentItem
                modal: true
                // using anchors can be tricky with scale animations
                x: (parent.width - width) / 2
                y: (parent.height - height) / 2
                height: 500
                width: 300
                padding: 0
        
                Text {
                    anchors.centerIn: parent
                    text: "Click outside to close"
                }
        
                background: Rectangle {
                    anchors.fill: parent
                    color: "#468055"
                    radius: 15
                }
        
                enter: Transition {
                    ParallelAnimation {
                        // animate opacity from 0 to 1 for a more continuous animation
                        NumberAnimation {
                            properties: "opacity"
                            from: 0
                            to: 1
                            duration: 64
                        }
                        NumberAnimation {
                            properties: "scale"
                            from: 0.75
                            to: 1
                            duration: 64
                        }
                    }
                }
                exit: Transition {
                    ParallelAnimation {
                        NumberAnimation {
                            properties: "opacity"
                            from: 1
                            to: 0
                            duration: 64
                        }
                        NumberAnimation {
                            properties: "scale"
                            from: 1
                            to: 0.75
                            duration: 64
                        }
                    }
                }
            }
            Button {
                anchors.centerIn: parent
                onClicked: animatedPopup.open()
                text: "Open"
            }
        }
        
        K Offline
        K Offline
        Kamichanw
        wrote on last edited by
        #3

        @lemons However, only Popup has exit and enter.

        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