QML Animations
QML Animations
Training Course
Visit us at http://qt.digia.com
Produced by Digia Plc.
Material based on Qt 5.0, created on September 27, 2012
Digia Plc.
Module: Animations
Animations
Easing Curves
Animation Groups
2/30
Animations
Objectives
Can apply animations to user interfaces:
Understanding of basic concepts
number and property animations
easing curves
3/30
Animations
Module: Animations
Animations
Easing Curves
Animation Groups
Animations
4/30
Animations
Demo
qml-animations/ex-thumbnailexplorer/thumbnailexplorer.qml
.
Animations
5/30
Animations
Animations
Animations can be applied to any element
Animations update properties to cause a visual change
All animations are property animations
Specialized animation types:
Animations
6/30
Animations
Number Animations
import QtQuick 2.0
Rectangle {
width: 400; height: 400
color: "lightblue"
Image {
x: 220
source: "../images/backbutton.png"
NumberAnimation on y {
from: 350; to: 150
duration: 1000
}
}
}
.Demo qml-animations/ex-animations/number-animation.qml
Animations
7/30
Animations
Number Animations
Number animations change the values of numeric properties
NumberAnimation on y {
from: 350; to: 150
duration: 1000
}
Animations
8/30
Animations
Property Animations
import QtQuick 2.0
Rectangle {
width: 400; height: 400; color: "lightblue"
Image {
id: image
x: 100; y: 100
source: "../images/thumbnails.png"
}
PropertyAnimation {
target: image
properties: "width,height"
from: 0; to: 200; duration: 1000
running: true
}
}
.Demo qml-animations/ex-animations/property-animation.qml
Animations
9/30
Animations
Property Animations
Property animations change named properties of a target
PropertyAnimation {
target: image
properties: "width,height"
from: 0; to: 200; duration: 1000
running: true
}
Animations
10/30
Animations
Animations
11/30
Animations
Animations
12/30
Animations
changes.
Behavior on x {
SpringAnimation {
spring: 1
damping: 0.2
}
}
Demo
qml-animations/ex-animations/spring-animation.qml
.
Animations
13/30
Animations
Module: Animations
Animations
Easing Curves
Animation Groups
Easing Curves
14/30
Animations
Easing Curves
import QtQuick 2.0
Rectangle {
width: 400; height: 400
color: "lightblue"
Image {
x: 220
source: "../images/backbutton.png"
NumberAnimation on y {
from: 0; to: 350
duration: 1000
easing.type: "OutExpo"
}
}
}
.Demo qml-animations/ex-animations/easing-curve.qml
.Demo $QTDIR/examples/animation/easing
Easing Curves
15/30
Animations
Easing Curves
Apply an easing curve to an animation:
NumberAnimation on y {
from: 0; to: 350; duration: 1000
easing.type: "OutExpo"
}
Easing Curves
16/30
Animations
Module: Animations
Animations
Easing Curves
Animation Groups
Animation Groups
17/30
Animations
For example:
a rescaling animation, followed by
an opacity changing animation
For example:
simultaneous rescaling and opacity changing animations
Animation Groups
18/30
Animations
Sequential Animations
Image {
id: rocket
anchors.centerIn: parent
source: "../images/rocket.png"
}
SequentialAnimation {
NumberAnimation {
target: rocket; properties: "scale"
from: 1.0; to: 0.5; duration: 1000
}
NumberAnimation {
target: rocket; properties: "opacity"
from: 1.0; to: 0.0; duration: 1000
}
running: true
}
Demo
qml-animations/ex-animations/sequential-animation.qml
.
Animation Groups
19/30
Animations
Sequential Animations
SequentialAnimation {
NumberAnimation {
target: rocket; properties: "scale"
from: 1.0; to: 0.5; duration: 1000
}
NumberAnimation {
target: rocket; properties: "opacity"
from: 1.0; to: 0.0; duration: 1000
}
running: true
}
Animation Groups
20/30
Animations
Animation Groups
21/30
Animations
Parallel Animations
Image {
id: rocket
anchors.centerIn: parent
source: "../images/rocket.png"
}
ParallelAnimation {
NumberAnimation {
target: rocket; properties: "scale"
from: 1.0; to: 0.5; duration: 1000
}
NumberAnimation {
target: rocket; properties: "opacity"
from: 1.0; to: 0.0; duration: 1000
}
running: true
}
.Demo qml-animations/ex-animations/parallel-animation.qml
Animation Groups
22/30
Animations
Other Animations
Other animations
motion
PropertyAction the PropertyAction element allows immediate property
Animation Groups
23/30
Animations
Color Animation
ColorAnimation describes color changes to items
Component-wise blending of RGBA values
ColorAnimation {
target: rectangle1
property: "color"
from: Qt.rgba(0,0.5,0,1)
to: Qt.rgba(1,1,1,1)
duration: 1000
running: true
}
Animation Groups
24/30
Animations
Rotation Animation
RotationAnimation describes rotation of items
Easier to use than NumberAnimation for the same purpose
Applied to the rotation property of an element
Value of direction property controls rotation:
RotationAnimation.Clockwise
RotationAnimation.Counterclockwise
RotationAnimation.Shortest the direction of least angle between
from and to values
Animation Groups
25/30
Animations
Rotation Animation
Image {
id: ball
source: "../images/ball.png"
anchors.centerIn: parent
smooth: true
RotationAnimation on rotation {
from: 45; to: 315
direction: RotationAnimation.Shortest
duration: 1000
}
}
1 second animation
Counter-clockwise from 45 to 315
shortest angle of rotation is via 0
Animation Groups
26/30
Animations
Path Animation
PathAnimation animates an item along a path
Manipulates the x, y and rotation properties of an element
The target element will be animated along the path
Value of orientation property controls the target rotation:
PathAnimation.Fixed
PathAnimation.RightFirst
PathAnimation.LeftFirst
PathAnimation.TopFirst
PathAnimation.BottomFirst
Animation Groups
27/30
Animations
Path Animation
PathAnimation {
duration: 2000
easing.type: Easing.InOutQuad
target: rocket
orientation: PathAnimation.RightFirst
anchorPoint: Qt.point(rocket.width/2,
rocket.height/2)
path: Path {
startX: rocket.width/2
startY: rocket.height/2
PathCubic {
x: window.width - rocket.width/2
y: window.height - rocket.height/2
control1X: x; control1Y: rocket.height/2
control2X: rocket.width/2; control2Y: y
}
}
}
.Demo qml-animations/ex-animations/path-animation.qml
Animation Groups
28/30
Animations
Animation Groups
29/30
Animations
Digia Plc.
Digia, Qt and the Digia and Qt logos are the registered trademarks of
Digia Plc. in Finland and other countries worldwide.
Animation Groups
30/30
Animations