c++qtuser-interfaceanimationqtgui

Qt GUI animations?


A bit of a peculiar question but I recently discovered that there is a way to make animations for Qt GUIs. I really want to find a way to have my main window expand into a larger one, but rather instead of having it instantly resized(which is rather simple to do) I'd like to see it expand in sort of an animation. More importantly, what is the proper way of doing such animations?

I am attaching 2 pictures showing the initial window and the final expanded one (or at least how I envision it).

----

enter image description here

(it needs to expand gradually, animation wise, into the following)

enter image description here

Thank you all, in advance.


Solution

  • Since you are using QML, that makes this rather simple for you. The easiest route would be to use a behavior combined with a smoothed animation. Trivial example below.

    ApplicationWindow {
        width: base.size
        height: base.size
        Item {
            id: base
            property real size: 400
            Behavior on size {
                SmoothedAnimation {
                    duration: 1000
                }
            }
            anchors.fill: parent
            MouseArea {
                anchors.fill: parent
                onClicked: base.size += 100
            }
        }
    }