Qtquick Module 002
Qtquick Module 002
Qtquick Module 002
Module Two
Module Two
Objectives
1 Positioning elements
Absolute positioning
Relative positioning Anchors
Module Two
Objectives
Module Two
Topics
1 Positioning elements
2 Making things move 3 QtQuick and Javascript are good friends 4 Questions 5 Lab
Positioning elements
Absolute positioning
Define the item's position and size relative to its parent
Positioning elements
Relative positioning
Anchors provide a way to position an item by specifying its relationship with other items
anchors
Item { width: 400; height: 400 Image { anchors.fill: parent source: "images/background.png } Spaceship { id: spaceship anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter } }
See video: addon/module-002/videos/anchors-positioners.mov
Positioning elements
Module Two
Topics
1 Positioning elements
2 Making things move 3 QtQuick and Javascript are good friends 4 Questions 5 Lab
All properties not expressed will be the same as the base state
or
Image { id: button; source: "images/button.png" y: 50; x: 10 MouseArea { id:mouseArea; anchors.fill: parent } } states: State { name: "leftXMove"; when: mouseArea.clicked PropertyChanges { target: myItem; x: 200 } }
Using when method. It will change the property but inside the state element
target
the animated elements id
properties
the property that you want to change during the animation. This can be an array of properties
easing.type
choose an easing curve to add a specific effect to your animation
Animation types
There are many ways to achieve your needs
NumberAnimation
ParallelAnimation
SequentialAnimation PauseAnimation RotationAnimation
NumberAnimation
This allows you to animate changes in a real number type property
... NumberAnimation { properties: "x, y"; duration: 500; easing.type: Easing.OutExpo; } ...
This is the basic animation element. Most animations are about changing numbers.
ParallelAnimation
ParallelAnimation { NumberAnimation { target : myRect properties: "x"; duration: 500; easing.type: Easing.OutExpo; } NumberAnimation { target : myRect properties: "y"; duration: 500; easing.type: Easing.OutExpo; } }
SequentialAnimation
SequentialAnimation { NumberAnimation { target : myRect properties: "x"; duration: 500; easing.type: Easing.OutExpo; } NumberAnimation { target : myRect properties: "y"; duration: 500; easing.type: Easing.OutExpo; } }
ParallelAnimation
SequentialAnimation
Module Two
Topics
1 Positioning elements
2 Making things move 3 QtQuick and Javascript are good friends 4 Questions 5 Lab
function randomState() { var statesArray = ["topLeft", "topRight", "bottomLeft", "bottomRight"]; var randomNumber = Math.floor(Math.random()*statesArray.length); return statesArray[randomNumber]; }
This is a simple function that picks a number and references it in an array of states
import QtQuick 1.0 import "random.js" as RandomFunction Item { id: myItem width: 400 ... MouseArea { anchors.fill: parent onClicked: { myItem.state = RandomFunction.randomState(); } } }
Button.qml
Button.qml
Button.qml
Module Two
Topics
1 Positioning elements
2 Making things move 3 QtQuick and Javascript are good friends
4 Questions
5 Lab
Questions
How do you create animations between states? What is the difference between Sequential and Parallel Animations? What happens if I dont declare the from and to transition properties? How do I create a javascript function inside a QtQuick file?
Module Two
Topics
1 Positioning elements
2 Making things move 3 QtQuick and Javascript are good friends
4 Questions
5 Lab
Lab
The full license text is available here:http://creativecommons.org/licenses/bysa/2.5/legalcode Nokia, Qt and the Nokia and Qt logos are the registered trademarks of Nokia