Namespaces
Variants
Actions

Enabling Qt Animation Framework in an application

Jump to: navigation, search
Article Metadata

Code Example
Tested with
Devices(s): Symbian, Windows

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

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.
181 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