-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartbutton.cpp
89 lines (84 loc) · 2.78 KB
/
startbutton.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<QPushButton>
#include "startbutton.h"
#include<QDebug>
#include<QPropertyAnimation>
StartButton::StartButton(QString normalImg,QString pressImg){
//保存两个路径
this->normalImgPath=normalImg;
this->pressImgPath=pressImg;
QPixmap pix;
bool ret=pix.load(this->normalImgPath);
if(!ret){
QString str=QString("1% 图片加载失败").arg(this->normalImgPath);
qDebug()<<str;
return;
}
//设定图片大小
this->setFixedSize(pix.width(),pix.height());//pix.width(),pix.height();
//设置不规则图片的样式
this->setStyleSheet("QPushButton{border:0px;}");
//设置图标
this->setIcon(pix);
//设置图片大小
this->setIconSize(QSize(pix.width(),pix.height()));
}
void StartButton::zoom1(){
QPropertyAnimation *animation=new QPropertyAnimation(this,"geometry");
//设定时间间隔
animation->setDuration(300);
//设定动画对象起始位置
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 StartButton::zoom2(){
QPropertyAnimation *animation=new QPropertyAnimation(this,"geometry");
//设定时间间隔
animation->setDuration(300);
//设定动画对象起始位置
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();
}
void StartButton::mousePressEvent(QMouseEvent*e){
if(this->pressImgPath != " ")
{
QPixmap pix1;
bool ret=pix1.load(this->pressImgPath);
if(!ret)
{
qDebug()<<"wrong"<<this->pressImgPath;
return;
}
this->setFixedSize(pix1.width(),pix1.height());
this->setStyleSheet("QPushButton{border:0px;}");
this->setIcon(pix1);
this->setIconSize(QSize(pix1.width(),pix1.height()));
}
//其他交给父类
QPushButton::mousePressEvent(e);
}
void StartButton::mouseReleaseEvent(QMouseEvent*e){
if(this->pressImgPath!=" ")
{QPixmap pix1;
bool ret=pix1.load(this->normalImgPath);
if(!ret){
qDebug()<<"wrong";
return;
}
this->setFixedSize(pix1.width(),pix1.height());
this->setStyleSheet("QPushButton{border:0px;}");
this->setIcon(pix1);
this->setIconSize(QSize(pix1.width(),pix1.height()));
}
//其他交给父类
QPushButton::mouseReleaseEvent(e);
}