Namespaces
Variants
Actions
Revision as of 04:16, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Animation with Transformation in Qt

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): 5800 xpress muzic

Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition

Article
Keywords: QGraphicsItem,QGraphicsItemAnimation
Created: mind_freak (20 Jun 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This article shows how to rotate and move a QGraphicsItem using the simple animation support provided by QGraphicsItemAnimation.


Preconditions

  • Download and install the Qt SDK

Property

  • Sets the Z-value, or the elevation, of the item, to z. The elevation decides the stacking order of sibling (neighboring) items
text->setZValue(5.0);
  • Sets the rotation of the item at the given step value to the angle specified.
animation->setRotationAt(i / 300.0, i);

SourceCode

main.cpp

#include <QtGui/QApplication>
#include "animation.h"
#include<QGraphicsItemAnimation>
#include<QPointF>
#include<QTimeLine>
#include<QGraphicsItem>
#include<QGraphicsSimpleTextItem>
#include<QGraphicsScene>
#include<QGraphicsView>
#include<QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
 
QGraphicsItem *text = new QGraphicsSimpleTextItem("Viral");
text->setAcceptDrops(1);
//text->setOpacity(0.0);
text->setAcceptHoverEvents(true);
text->setZValue(5.0);
QHBoxLayout *lay=new QHBoxLayout();
QTimeLine *timer = new QTimeLine(5000);
timer->setFrameRange(0, 100);
 
QGraphicsItemAnimation *animation = new QGraphicsItemAnimation();
animation->setItem(text);
animation->setTimeLine(timer);
int i;
for (i = 0; i <= 250; ++i)//getting the coordinates
animation->setPosAt(i/250.0,QPointF(i, i));//positioning the graphicsItem
 
animation->setRotationAt(i / 300.0, i);//rotation of graphicsItem.
 
 
 
 
QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(0, 0, 250, 250);//rectuangular scene built
scene->addItem(text);
 
QGraphicsView *view = new QGraphicsView(scene);
view->show();
 
timer->start();//start timer to view animation
 
return a.exec();
}

ScreenShot

Animation001.jpg

175 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved