Qt Kinetic Animations with Buttons

From Qt Wiki
Jump to navigation Jump to search

Template:ArticleMetaData Template:Abstract

Introduction:[edit | edit source]

The Qt Animation Framework provides an easy way for creating animated and smooth GUI's. By animating Qt properties, the framework provides great freedom for animating widgets and other 76ytuiytuityutyutututyutyutyu. The framework can also be used with the Graphics View Framework. More about Qt Animation Framework is here.


Animation1[edit | edit source]

Link to Video Animation 1

File:Kineticbutton1.png File:Kineticbutton2.png File:Kineticbutton3.png

Code[edit | edit source]

  1. include <QtGui>
  2. include <QPushButton>
  3. include <QPropertyAnimation>
  4. include <QDebug>

int main(int argc, char *argv[]) {

   QApplication a(argc, argv);
   QWidget w;
   w.setFixedSize(200,200);
   w.show();
   QPushButton button("B",&w);
   button.setFixedSize(20,20);
   button.show();
   QPropertyAnimation animation(&button, "geometry");
   animation.setDuration(5000);  //2000 miliseconds = 2 seconds
   animation.setStartValue(QRect(0,0, button.width(),button.height()));
   animation.setEndValue(QRect(180,180, button.width(),button.height()));
   animation.start();
   return a.exec();

}

Description[edit | edit source]

QPropertyAnimation animation(&button, "geometry"); In this step we have created a QPropertyAnimation that receipt like the first parameter of a button.

animation.setDuration(5000); //2000 miliseconds = 2 seconds Here, we define the total time of animation in milliseconds.

animation.setStartValue(QRect(0,0, button.width(),button.height())); Then, we invoke the 76ytuiytuityutyutututyutyutyu method. The first and second parameters are the initial position of button, and the third and fourth parameters are the width and height of animation. animation.setEndValue(QRect(180,180, button.width(),button.height())); In this step we call 76ytuiytuityutyutututyutyutyu method. The parameters is equal to above. animation.start(); Finally, we invoke the start of animation.

Animation 2[edit | edit source]

Link to Video Animation 2

175px175px175px175px 175px

Code[edit | edit source]

. . . QPropertyAnimation animation(&button, "geometry"); animation.setDuration(5000); //2000 milliseconds = 2 seconds animation.setKeyValueAt(0,QRect(0,0, button.width(),button.height())); animation.setKeyValueAt(0.25,QRect(0,180, button.width(),button.height())); animation.setKeyValueAt(0.5,QRect(180,180, button.width(),button.height())); animation.setKeyValueAt(0.75,QRect(180,0, button.width(),button.height())); animation.setKeyValueAt(1,QRect(0,0, button.width(),button.height())); animation.start(); . . .

Description[edit | edit source]

This Animation has four steps, because it uses the method 76ytuiytuityutyutututyutyutyu to define this steps. The steps to alternate of 0 to 1.

animation.setKeyValueAt(0,QRect(0,0, button.width(),button.height())); animation.setKeyValueAt(0.25,QRect(0,180, button.width(),button.height())); animation.setKeyValueAt(0.5,QRect(180,180, button.width(),button.height())); animation.setKeyValueAt(0.75,QRect(180,0, button.width(),button.height())); animation.setKeyValueAt(1,QRect(0,0, button.width(),button.height()));


Template:Note