AnchorAnimation as a Behavior



  • According to the documentation it should be possible to use AnchorAnimation as a behavior.
    From https://qt-project.org/doc/qt-4.8/qml-anchoranimation.html

    bq. Like any other animation element, an AnchorAnimation can be applied in a number of ways, including transitions, behaviors and property value sources.

    I cannot get it to work. Please see the following simple example:
    @import QtQuick 1.1

    Item {
    id: app
    width: 1024
    height: 768

    Item {
    anchors.centerIn: parent
    width: parent.width/2
    height: parent.height/2

    Rectangle {
    id: red
    color: 'red'
    width: 100
    height: 100
    anchors.verticalCenter: parent.verticalCenter
    anchors.left: parent.left
    MouseArea {
    anchors.fill: parent
    onClicked: itm.alignItem = red
    }
    }
    Rectangle {
    id: green
    color: 'green'
    width: 100
    height: 100
    anchors.verticalCenter: parent.verticalCenter
    anchors.right: parent.right
    MouseArea {
    anchors.fill: parent
    onClicked: itm.alignItem = green
    }
    }

    Rectangle {
    id: itm
    color: 'blue'
    property Item alignItem: red
    anchors.fill: alignItem
    Behavior on anchors {
    AnchorAnimation { duration: 1000 }
    }
    }
    }
    }
    @

    I must change the property alignItem and not use states since the items that itm is supposed to anchor to is created dynamically. Creating a state for every "anchoring-possibility" is not working.

    I have also tried this:
    @Behavior on anchors.fill {
    AnchorAnimation { duration: 1000 }
    }@

    and

    @Behavior {
    AnchorAnimation {
    targets: [
    itm
    ]
    duration: 1000
    }
    }@



  • Hi Micke,

    Look in Documentation for "AnchorAnimation"

    It says:

    Note: AnchorAnimation can only be used in a Transition and in conjunction with an AnchorChange. It cannot be used in behaviors and other types of animations...

    Rgds, Steven



  • Where did you find that note? I cannot find it in the link I posted. Is explains why it doesn't work but it strange that they say it should work in the quote above.



  • Qt Help (in Qt Creator)

    -> Look for AnchorAnimation

    -> Detailed Description, Note...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.