Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Dynamic attached Behavior

    QML and Qt Quick
    1
    1
    215
    Loading More Posts
    • 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.
    • benlau
      benlau Qt Champions 2016 last edited by

      Hi,

      Is it possible to attach a Behavior object to a QML item dynamically?

      For example, take out the "Behavior on width" from the code, and assign another "Behavior" after construction by code?

      import QtQuick 2.0
      
      Rectangle {
          id: rect
          width: 100; height: 100
          color: "red"
      
          Behavior on width {
              NumberAnimation { duration: 1000 }
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: rect.width = 50
          }
      }
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post