[Interest] Updating NumberAnimation from/to at runtime

Kristoffersen, Even (NO14) Even.Kristoffersen at Honeywell.com
Fri Jul 14 14:59:41 CEST 2017


You can try to force binding with Qt.binding().

-Even

From: Interest [mailto:interest-bounces+even.kristoffersen=honeywell.com at qt-project.org] On Behalf Of Shantanu Tushar
Sent: 14. juli 2017 11:27
To: interest at qt-project.org
Subject: [Interest] Updating NumberAnimation from/to at runtime

Hi,
Consider the following code which draws two rectangles - a red rectangle which contains another blue rectangle.

Rectangle {
        id: r1
        anchors.centerIn: parent
        width: 300; height: 100
        color: "red"

        Rectangle {
            id: r2
            width: 100; height: 100
            color: "blue"

            NumberAnimation on x {
                loops: Animation.Infinite
                from: 0; to: r1.width-r2.width
                duration: 1000

                onToChanged: console.log(to)
            }
        }

        NumberAnimation on width {
            loops: Animation.Infinite
            from: 300; to: 100
            duration: 10000
        }
    }
The blue rectangle is supposed to keep moving inside the red rectangle by means of a NumberAnimation. However, the width of the red rectangle changes according to another animation.
I thought this will work fine and the blue rectangle will be confined to the red rectangle because of the following binding-

to: r1.width-r2.width
However, thats not what happens. The blue rectangle overflows the red rectangle, as if the binding never got updated. But, I can see that the `console.log(to)` does prove the binding is working.

(Screenshot at http://i.imgur.com/yDTYbv9.png<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fi.imgur.com%2FyDTYbv9.png&data=02%7C01%7Ceven.kristoffersen%40honeywell.com%7C5b50a750b34e473ffd8708d4ca9a91e0%7C96ece5269c7d48b08daf8b93c90a5d18%7C0%7C0%7C636356212616706749&sdata=D17jHatSL1gf3XFPYQpAebB2e1H7T7nmzhLvi%2BPcB5g%3D&reserved=0> )
Is this a limitation of NumberAnimation? Or am I using it wrong?

--
Shantanu Tushar    (UTC +0530)
shantanu.io<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fshantanu.io&data=02%7C01%7Ceven.kristoffersen%40honeywell.com%7C5b50a750b34e473ffd8708d4ca9a91e0%7C96ece5269c7d48b08daf8b93c90a5d18%7C0%7C0%7C636356212616706749&sdata=E80rwaltPVsx1m%2FToEC8aIY1%2F9fwpeFCfxrLlThOxTs%3D&reserved=0>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170714/95955c75/attachment.html>


More information about the Interest mailing list