Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. AnchorAnimation as a Behavior
Forum Updated to NodeBB v4.3 + New Features

AnchorAnimation as a Behavior

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    micke.prag
    wrote on last edited by
    #1

    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
    }
    }@

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on last edited by
      #2

      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

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • M Offline
        M Offline
        micke.prag
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stevenceuppens
          wrote on last edited by
          #4

          Qt Help (in Qt Creator)

          -> Look for AnchorAnimation

          -> Detailed Description, Note...

          Steven CEUPPENS
          Developer / Architect
          Mobile: +32 479 65 93 10

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved