Enabling Qt Animation Framework in an application
Article Metadata
Code Example
Tested with
Compatibility
S60 3rd Edition, FP2
S60 5th Edition
Maemo
Article
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
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.


(no comments yet)