×
Namespaces

Variants
Actions
(Difference between revisions)

Basic Animation in QML

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetaData)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
Line 36: Line 36:
 
    
 
    
 
Here we will link the default animation to when a property changes, so we will make a rectangle that follows the mouse click. This can be achieved by adding [http://doc.qt.nokia.com/4.7/qml-behavior.html Behavior] elements and adding a {{Icode|MouseArea}} like below.
 
Here we will link the default animation to when a property changes, so we will make a rectangle that follows the mouse click. This can be achieved by adding [http://doc.qt.nokia.com/4.7/qml-behavior.html Behavior] elements and adding a {{Icode|MouseArea}} like below.
<code cpp>
+
<code cpp-qt>
 
import QtQuick 1.0
 
import QtQuick 1.0
 
Item {
 
Item {
Line 58: Line 58:
 
By changing the {{Icode|PropertyAnimation}} we can bring a bit of easing effect in our rectangle like this
 
By changing the {{Icode|PropertyAnimation}} we can bring a bit of easing effect in our rectangle like this
 
   
 
   
<code cpp>
+
<code cpp-qt>
 
Behavior on x {
 
Behavior on x {
 
PropertyAnimation {
 
PropertyAnimation {

Latest revision as of 04:16, 11 October 2012

Article Metadata
Code ExampleTested with
Devices(s): N8
Compatibility
Platform(s): Symbian
Symbian
Article
Keywords: Animation
Created: somnathbanik (17 May 2014)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Overview

This article demonstrate how to perform basic animation in QML

[edit] Basic Idea

We will create an example that displays a rectangle with colors. When we click on the screen the rectangle moves with easing effects and animated to where the mouse is clicked.

AnimationQt.png

Note.pngNote: This is a very basic animation in QML for beginners

Here we will link the default animation to when a property changes, so we will make a rectangle that follows the mouse click. This can be achieved by adding Behavior elements and adding a MouseArea like below.

import QtQuick 1.0
Item {
width: 400; height: 400
Rectangle {
id: rect
width: 64; height: 64
color: "blue"
Behavior on x { PropertyAnimation { duration: 500 } }
Behavior on y { PropertyAnimation { duration: 500 } }
}
MouseArea {
anchors.fill: parent
onClicked: { rect.x = mouse.x; rect.y = mouse.y }
}
}

When the value of x and y changes in the Behavior declaration, it means it should animate over 500 milliseconds. Till now we have done animation without easing effects. The Easing property of animations has a number of attributes that control how the value should be varied. By changing the PropertyAnimation we can bring a bit of easing effect in our rectangle like this

Behavior on x {
PropertyAnimation {
duration: 500
easing.type: Easing.InOutElastic
easing.amplitude: 2.0
easing.period: 1.5
}
}
Behavior on y {
PropertyAnimation {
duration: 500
easing.type: Easing.InOutElastic
easing.amplitude: 2.0
easing.period: 1.5
}
}



[edit] Source Code

The full source code presented in this article is available here File:AnimationQt.zip


[edit] Related Articles on Animation

--somnathbanik 13:04, 17 May 2011 (EEST)

This page was last modified on 11 October 2012, at 04:16.
79 page views in the last 30 days.
×