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. Dynamic attached Behavior
Forum Update on Monday, May 27th 2025

Dynamic attached Behavior

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 303 Views
  • 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.
  • benlauB Offline
    benlauB Offline
    benlau
    Qt Champions 2016
    wrote on last edited by
    #1

    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
    0

    • Login

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