Enabling Qt Animation Framework in an application
Overview[edit | edit source]
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[edit | edit source]
Qt 4.6 has been installed.
Header file[edit | edit source]
The Qt Animation Framework supports the animation of graphics items derived from 76ytuiytuityutyutututyutyutyu and 76ytuiytuityutyutututyutyutyu or from 76ytuiytuityutyutututyutyutyu. Graphics items can be placed into 76ytuiytuityutyutututyutyutyu, so first we create it as the 76ytuiytuityutyutututyutyutyu central widget.
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
Source file[edit | edit source]
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[edit | edit source]
The application has 76ytuiytuityutyutututyutyutyu and 76ytuiytuityutyutututyutyutyu ready to show some animations.