![Qt5 C++ GUI Programming Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/790/36698790/b_36698790.jpg)
上QQ阅读APP看书,第一时间看更新
How to do it…
In the following example, we will create a new widget project and animate the push button by changing its properties:
Let's create a new Qt Widgets Application project. After that, open up mainwindow.ui with Qt Designer and place a button on the main window, as shown here:
![](https://epubservercos.yuewen.com/B40C46/19470380801500706/epubprivate/OEBPS/Images/e8af7acb-83d7-4175-bcb4-8e662dd63b31.png?sign=1739294878-vfzYsTnoeWuYrUVBgD6il2hL9OBmSQ3f-0-a64c660c0751d5cfa31fc695b96f2e51)
Open up mainwindow.cpp and add the following line of code at the beginning of the source code:
#include <QPropertyAnimation>
- After that, open up mainwindow.cpp and add the following code to the constructor:
QPropertyAnimation *animation = new QPropertyAnimation(ui->pushButton, "geometry");
animation->setDuration(10000);
animation->setStartValue(ui->pushButton->geometry());
animation->setEndValue(QRect(200, 200, 100, 50));
animation->start();