参考代码如下:
.h文件
#ifndef MOVEWIDGET_H
#define MOVEWIDGET_H
#include <QtGui/QWidget>
#include <qpropertyanimation.h>
#include <QLabel>
#include <QApplication>
class MoveWidget : public QWidget
{
Q_OBJECT
public:
MoveWidget(QWidget *parent = 0)
~MoveWidget()
private:
void star()
private:
QPropertyAnimation *animation,
*animation2
QLabel *myWidget,
*myWidget2
QString path
}
#endif // MOVEWIDGET_H
.cpp文件
#include "movewidget.h"
#include "qsequentialanimationgroup.h"
#include "qparallelanimationgroup.h"
MoveWidget::MoveWidget(QWidget *parent)
: QWidget(parent)
{
this->path = QApplication::applicationDirPath()
this->myWidget = new QLabel(this)
this->myWidget2 = new QLabel(this)
this->animation = new QPropertyAnimation(myWidget,"geometry")
this->animation2 = new QPropertyAnimation(myWidget2,"geometry")
//常见QPropertyAnimation对象,关联了myWidget这个窗体的几何属性
this->star()
}
void MoveWidget::star()
{
this->myWidget->setPixmap(QPixmap(this->path + "/hello.png"))
this->myWidget2->setPixmap(QPixmap(this->path + "/hello1.png"))
this->animation->setDuration(2000)//速度,越小越快
this->animation->setStartValue(QRect(0,0,158,168))
this->animation->setEndValue(QRect(250,250,158,168))
// this->animation->setEasingCurve(QEasingCurve::OutBounce)//outbounce有一个缓冲的现象
// this->animation->setEasingCurve(QEasingCurve::OutBack)//outback缓慢降落
// this->animation->setEasingCurve(QEasingCurve::OutCirc)//outcirc和outback差不多
this->animation->setEasingCurve(QEasingCurve::OutInQuart)
this->animation->start()
this->animation2->setDuration(2000)
this->animation2->setStartValue(QRect(0,360,158,168))
this->animation2->setEndValue(QRect(110,180,158,168))
this->animation2->setEasingCurve(QEasingCurve::OutBounce)
this->animation2->start()
}
MoveWidget::~MoveWidget()
{
}
1、双击运行软件,d出启动向导对话框,点击打开一个现有的图象文件前面的黄色按钮,在打开图象文件对话框中选择并打开要进行设置的gif图片。2、在编辑菜单下找到并点击全局信息,有两种情况,一种是设置gif图片为无限循环播放,另外一种就是输入相关的数值来控制播放的次数。
3、让gif图片一直不停循环播放,只需要在无限前面勾选就行了,点击确定按钮就行了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)