Skip to content
Tino Pyssysalo edited this page May 15, 2018 · 10 revisions

Behaviour (P1 | 1h)

Explanation of the contents of a topic page @ Week 1 Topic 1

Back to Week 2

Objective: Basic animation

Beginner

  • What does "easing curve" mean?

Intermediate

  • What is Behaviour?
  • When does Behaviour animate an item property?
  • When does the animation start?
  • When does the animation finish?
  • What is an easing curve?
  • How do you define non-linear animations?

Expert

Omitted


Course material content

Comment: What is an easing curve (or how to define non-linear animations, it would be nice to show/mention Qt Quick Toolbar in Qt Creator QML editor?)

K: I have completely missed the light bulbs so I think the toolbars should be mentioned sooner somewhere too https://doc.qt.io/qtcreator/qt-quick-toolbars.html

Behavior

http://doc.qt.io/qt-5/qml-qtquick-behavior.html#details

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 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
      }
  }

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 Qt Quick Behaviors with States.

E: I copied this from the link in the description. States and transitions don't appear until 2.14, and there's alot of talk about the states and transitions in the text. Should this text be redone somehow or should we put states and transitions before Behavior?

Tino: Quite a corner case in my opinion. I did not even know this. Who would use both at the same time? I would put this piece of text to the section, where we talk about states and transitions. Actually, it's there in the end of 2.14 already.

Instructions and description for the exercise of the topic


Exhaustive reference material mentioned in this topic

Further reading topics/links:

Clone this wiki locally