Namespaces
Variants
Actions

Archived:Using QSequentialAnimationGroup with QGraphicsTextItem

Jump to: navigation, search
Archived.png
Archived: 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

Compatibility
Platform(s): All platforms supported by Qt

Article
Keywords: QSequentialAnimationGroup, QPropertyAnimation, QGraphicsTextItem
Created: User:Kbwiki (20 Oct 2010)
Last edited: hamishwillee (11 Oct 2012)

Description

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.

Solution

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
{
Q_OBJECT
 
public:
MainWindow( QWidget* parent = 0 );
~MainWindow() {}
 
private:
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();
m_scene.setSceneRect(screenRect);
 
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 );
animGroup->start();
}
 
 
#include "main.moc"
 
int main( int argc, char *argv[] )
{
QApplication a( argc, argv );
MainWindow w;
w.showMaximized();
return a.exec();
}
This page was last modified on 11 October 2012, at 04:15.
126 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