Behavior Element Reference

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

This element was introduced in Qt 4.7.

Detailed Description

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

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:

  1. import QtQuick 1.0
  2.  
  3. Rectangle  {
  4.     id: rect
  5.     width: 100; height: 100
  6.     color: "red"
  7.  
  8.     Behavior on width  {
  9.         NumberAnimation  { duration: 1000 }
  10.     }
  11.  
  12.     MouseArea  {
  13.         anchors.fill: parent
  14.         onClicked: rect.width = 50
  15.     }
  16. }

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. For general advice on using Behaviors to animate state changes, see Using QML Behaviors with States.

Properties

Property Documentation

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

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

By default a Behavior is enabled.

Notes provided by the Qt Community

No notes