Important: Please read the Qt Code of Conduct -

Animate an anchored object.

  • Hi,

    I have a problem: I created an Item that has an image (on a separate qml file) then in the main.qml program I anchored this object to the screen. My needs as to center, so I anchored the object with

    @anchors.vericalCenter = screen.verticalCenter
    anchors.horizontalCenter = screen.horizontalCenter@

    This works correctly, but I need to apply a behavioral animation on a boolean flag that sounds like

    @Behavior on boolean_flag { ... }@

    The animation I need is a movement along the y axis. What I see is that is this axis is anchored, obviously it cant' be moved changing the value of its 'y' property. What property I will use to move the object ?

  • Hi,

    You can use the "AnchorAnimation": element to animate changes to the anchors.

    Alternatively, you could try to animate the anchors.verticalCenterOffset property with a NumberAnimation, which will also effectively change the y value.


  • Thank you very much, mbrasser.

    My question seems silly, but I was trying to disentangle myself in the various animations options to decide the best strategy.

    I see that there are two possibilities to do animations:

    • Create the Item, i.e. an image, and a property (the animation) Then act on this custom property with a trigger, a behavior etc.
    • Create the Item, i.e. an image, (and if needed other optional elements) Then create a NumberAnimation.

    Actually I am working with the second strategy: what is the preferred strategy between these two different approaches? I find troubles to manage animation properties, but it seems to me that if the animation should even occur defining this as an object property is the best way (I used this for multi-state buttons)

    Thank you

Log in to reply