Qt Reference Documentation

QML Behavior Element

The Behavior element allows you to specify a default animation for a property change. More...

  • List of all members, including inherited members
  • Properties

    Detailed Description

    A Behavior defines the default animation to be applied whenever a particular property value changes.

    For example, the following Behavior defines a NumberAnimation to be run whenever the Rectangle's width value changes. When the MouseArea is clicked, the width is changed, triggering the behavior's animation:

     import Qt 4.7
     Rectangle {
         id: rect
         width: 100; height: 100
         color: "red"
         Behavior on width {
             NumberAnimation { duration: 1000 }
         MouseArea {
             anchors.fill: parent
             onClicked: rect.width = 50

    Note that a property cannot have more than one assigned Behavior. To provide multiple animations within a Behavior, use ParallelAnimation or SequentialAnimation.

    If a state change has a Transition that matches the same property as a Behavior, the Transition animation overrides the Behavior for that state change.

    See also QML Animation, Behavior example, and QtDeclarative.

    Property Documentation

    defaultanimation : Animation

    This property holds the animation to run when the behavior is triggered.

    enabled : bool

    This property holds whether the behavior will be triggered when the tracked property changes value.

    By default a Behavior is enabled.


    Thank you for giving your feedback.

    Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.

    [0]; s.parentNode.insertBefore(ga, s); })();