Archived:Using QSequentialAnimationGroup with QGraphicsTextItem

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.

Article Metadata
Tested with
Devices(s): Tested on Nokia 5800 XpressMusic
Platform(s): All platforms supported by Qt
S60 5th Edition
Keywords: QSequentialAnimationGroup, QPropertyAnimation, QGraphicsTextItem
Created: User:Kbwiki (20 Oct 2010)
Last edited: hamishwillee (11 Oct 2012)


QSequentialAnimationGroup, derived from QAnimationGroup, can be used to run a number of animations in sequence, starting the next animation after one has finished playing. The animations are played in the order they are added to the group (using addAnimation() or insertAnimation()). The animation group finishes when its last animation has finished.


The following piece of code demonstrates the usage of QSequentialAnimationGroup with QGraphicsTextItem objects.

  #include <QtGui/QApplication>
#include <QDesktopWidget>
#include <QMainWindow>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
class MainWindow : public QMainWindow
MainWindow( QWidget* parent = 0 );
~MainWindow() {}
QGraphicsScene m_scene;
QGraphicsTextItem* m_text1;
QGraphicsTextItem* m_text2;
MainWindow::MainWindow( QWidget* parent )
: QMainWindow( parent )
// Start and end positions of QGraphicsItem objects
QRect screenRect = QApplication::desktop()->availableGeometry();
QPointF startPos1( screenRect.right(), screenRect.bottom()/2 - 25 );
QPointF endPos1( startPos1 );
endPos1.rx() = 50;
QPointF startPos2( startPos1 );
startPos2.ry() += 50;
QPointF endPos2( endPos1 );
endPos2.ry() += 50;
m_text1 = new QGraphicsTextItem( "First line of text" );
m_text1->setPos( startPos1 );
m_scene.addItem( m_text1 );
m_text2 = new QGraphicsTextItem( "Second line of text" );
m_text2->setPos( startPos2 );
m_scene.addItem( m_text2 );
QPropertyAnimation* animText1 = new QPropertyAnimation( m_text1, "pos" );
animText1->setDuration( 1500 );
animText1->setStartValue( startPos1 );
animText1->setEndValue( endPos1 );
animText1->setEasingCurve( QEasingCurve::OutSine );
QPropertyAnimation* animText2 = new QPropertyAnimation( m_text2, "pos" );
animText2->setDuration( 1500 );
animText2->setStartValue( startPos2 );
animText2->setEndValue( endPos2 );
animText2->setEasingCurve( QEasingCurve::OutSine );
QGraphicsView* view = new QGraphicsView( &m_scene, this );
view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
setCentralWidget( view );
// Add the animation to a sequential animation group and start the animation
QSequentialAnimationGroup* animGroup = new QSequentialAnimationGroup( this );
animGroup->addAnimation( animText1 );
animGroup->addAnimation( animText2 );
#include "main.moc"
int main( int argc, char *argv[] )
QApplication a( argc, argv );
MainWindow w;
return a.exec();
This page was last modified on 11 October 2012, at 04:15.
58 page views in the last 30 days.