How to add animation to a component while destroying in QML
Unsolved
QML and Qt Quick
-
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!!!
-
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