-
Notifications
You must be signed in to change notification settings - Fork 0
/
mypushbotton.cpp
59 lines (50 loc) · 1.68 KB
/
mypushbotton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "mypushbotton.h"
MyPushBotton::MyPushBotton(QString imgpath)
{
this->imgpath = imgpath;
QPixmap pix;
bool ret = pix.load(this->imgpath);
if(!ret)
{
QString str = QString("%1 图片加载失败").arg(this->imgpath);
qDebug()<<str;
return;
}
this->setFixedSize(pix.width(),pix.height());
//设置不规则样式
this->setStyleSheet("QPushBotton{border:0px;}");
this->setIcon(pix);
this->setIconSize(QSize(pix.width(), pix.height()));
btnmusic = new QMediaPlayer(this);
btnmusic->setMedia(QUrl("qrc://res/music/button.wav"));
}
void MyPushBotton::Zoom1()
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
btnmusic->play();
//设定时间间隔
animation->setDuration(200);
//设置动态的起始位置
animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
//设置动画结束位置
animation->setEndValue(QRect(this->x(), this->y() + 10, this->width(), this->height()));
//设置曲线
animation->setEasingCurve(QEasingCurve::OutBounce);
//执行动画
animation->start();
}
void MyPushBotton::Zoom2()
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
btnmusic->play();
//设定时间间隔
animation->setDuration(200);
//设置动态的起始位置
animation->setStartValue(QRect(this->x(),this->y() + 10, this->width(), this->height()));
//设置动画结束位置
animation->setEndValue(QRect(this->x(), this->y(), this->width(), this->height()));
//设置曲线
animation->setEasingCurve(QEasingCurve::OutBounce);
//执行动画
animation->start();
}