PropertyAction Element Reference

The PropertyAction element allows immediate property changes during animation.

[Inherits Animation]

This element was introduced in Qt 4.7.

Detailed Description

The PropertyAction element allows immediate property changes during animation.

PropertyAction is used to specify an immediate property change during an animation. The property change is not animated.

It is useful for setting non-animated property values during an animation.

For example, here is a SequentialAnimation that sets the image's smooth property to true, animates the width of the image, then sets smooth back to false:

  1.                 SequentialAnimation  {
  2.     PropertyAction  { target: img; property: "smooth"; value: "true" }
  3.     NumberAnimation  { target: img; property: "width"; to: 300; duration: 1000 }
  4.     PropertyAction  { target: img; property: "smooth"; value: "false" }
  5. }

PropertyAction is also useful for setting the exact point at which a property change should occur during a Transition. For example, if PropertyChanges was used in a State to rotate an item around a particular transformOrigin, it might be implemented like this:

  1.                 Item  {
  2.     width: 400; height: 400
  3.  
  4.     Rectangle  {
  5.         id: rect
  6.         width: 200; height: 100
  7.         color: "red"
  8.  
  9.         states: State  {
  10.             name: "rotated"
  11.             PropertyChanges  { target: rect; rotation: 180; transformOrigin: Item.BottomRight }
  12.         }
  13.  
  14.         transitions: Transition  {
  15.             RotationAnimation  { duration: 1000; direction: RotationAnimation.Counterclockwise }
  16.         }
  17.  
  18.         MouseArea  {
  19.             anchors.fill: parent
  20.             onClicked: rect.state = "rotated"
  21.         }
  22.     }
  23. }

However, with this code, the transformOrigin is not set until after the animation, as a State is taken to define the values at the end of a transition. The animation would rotate at the default transformOrigin, then jump to Item.BottomRight. To fix this, insert a PropertyAction before the RotationAnimation begins:

  1. transitions: Transition  {
  2.     SequentialAnimation  {
  3.         PropertyAction  { target: rect; property: "transformOrigin" }
  4.         RotationAnimation  { duration: 1000; direction: RotationAnimation.Counterclockwise }
  5.     }
  6. }

This immediately sets the transformOrigin property to the value defined in the end state of the Transition (i.e. the value defined in the PropertyAction object) so that the rotation animation begins with the correct transform origin.

Properties

Property Documentation

  • exclude : list<Object>

This property holds the objects that should not be affected by this action.

See also targets.

These properties determine the items and their properties that are affected by this action.

The details of how these properties are interpreted in different situations is covered in the corresponding PropertyAnimation documentation.

See also exclude.

  • value : any

This property holds the value to be set on the property.

If the PropertyAction is defined within a Transition or Behavior, this value defaults to the value defined in the end state of the Transition, or the value of the property change that triggered the Behavior.

Notes provided by the Qt Community

No notes