×
Namespaces

Variants
Actions
Revision as of 04:16, 11 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Enabling Qt Animation Framework in an application

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): Symbian, Windows
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
Maemo
Symbian
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
Article
Keywords: QMainWindow, QGraphicsScene, QGraphicsView, QGraphicsItem
Created: tepaa (16 Dec 2009)
Last edited: hamishwillee (11 Oct 2012)


Contents

Overview

This series of snippets demonstrates how to implement nice animation effects into your Qt UI application. Qt 4.6 has Qt Animation Framework as a built-in feature. Documentation can be found here: [1]

This snippet is an example of an application that can show animation effects. Animations can be executed in the Qt Graphics View Framework: [2]

Full example code can be found here: File:Animation fw.zip

Animation fw.PNG


Preconditions

Qt 4.6 has been installed.


Header file

The Qt Animation Framework supports the animation of graphics items derived from QObject and QGraphicsItem or from QGraphicsObject. Graphics items can be placed into QGraphicsScene, so first we create it as the QMainWindow central widget.

class MainWindow : public QMainWindow
{
Q_OBJECT
 
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};


Source file

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Create QGraphicsScene and QGraphicsView
m_scene = new QGraphicsScene(this);
m_view = new QGraphicsView(m_scene,this);
m_view->setCacheMode(QGraphicsView::CacheBackground);
m_view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
// Create PictureItem for the animation
QPixmap pixmap(":/qt1.png");
m_item = new PictureItem(pixmap.size(),pixmap,this);
 
// Add PictureItem to center of the scene
m_scene->addItem(m_item);
 
createMenu();
 
// Set QGraphicsView as central widget
this->setCentralWidget(m_view);
}


Postconditions

The application has QGraphicsScene and QGraphicsView ready to show some animations.


Animation Framework snippet series

Full example code package

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