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?
Forum Updated to NodeBB v4.3 + New Features

How to customize animation on show and close?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 331 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, 16:24 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 14 Jul 2023, 06:31
    0
    • K Kamichanw
      13 Jul 2023, 16:24

      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 14 Jul 2023, 06:31 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 15 Jul 2023, 12:50
      0
      • L lemons
        14 Jul 2023, 06:31

        @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 15 Jul 2023, 12:50 last edited by
        #3

        @lemons However, only Popup has exit and enter.

        1 Reply Last reply
        0

        3/3

        15 Jul 2023, 12:50

        • Login

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