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 animation to a component while destroying in QML

How to add animation to a component while destroying in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
animationqtquick2qtquickcontrols
2 Posts 2 Posters 897 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.
  • P Offline
    P Offline
    pra7
    wrote on 13 Apr 2018, 10:56 last edited by
    #1

    I am adding Animation to my project and most of the UI is dynamic. Currently, i am not able to add animation to the Component while destroying. Following is the test application code which describes the same:

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        property bool removeClicked : true
    
        Row{
            anchors.bottom: parent.bottom
            spacing:20
            Button{
                text:"Add"
    
                onClicked: {
                    removeClicked = false
                    comp.createObject(myrow)
                }
            }
    
            Button{
                id:remBtn
                text:"Remove"
    
                onClicked: {
                    removeClicked = true
                    myrow.children[0].destroy() //Destroy the object
    
                }
            }
        }
    
        Row{
            id:myrow
            height:40
            spacing:20
        }
    
        Component{
            id:comp
            Rectangle{
                width:20
                height:30
                color: "red"
    
                NumberAnimation on opacity{
                    id: destroyAnimation
                    from :removeClicked ? 1:0
                    to: removeClicked ? 0:1
                    duration: 1000
                }
            }
        }
    }
    

    Any help will be Appreciated!!!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 13 Apr 2018, 11:49 last edited by
      #2

      Use model classes and views instead of such approach. It will save you a lot of tears in the long run.

      For a starter, see: https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html

      (Z(:^

      1 Reply Last reply
      1

      1/2

      13 Apr 2018, 10:56

      • Login

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