-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmypushbutton.cpp
More file actions
95 lines (90 loc) · 2.95 KB
/
Copy pathmypushbutton.cpp
File metadata and controls
95 lines (90 loc) · 2.95 KB
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
90
91
92
93
94
95
#include "mypushbutton.h"
#include<QDebug>
#include<QPropertyAnimation>
myPushButton::myPushButton(QString normalIconPath,QString pressIconPath)
{
this->nIP=normalIconPath;
this->cIP=pressIconPath;
QPixmap pix;
//检验图片是否加载成功
bool s=pix.load(this->nIP);
if(!s)
{
qDebug()<<"按钮图标加载失败!";
return;
}
//设置图片固定大小
this->setFixedSize(pix.width(),pix.height());
//设置不规则图片样式
this->setStyleSheet("QPushButton{border:0px};");
//设置图标
this->setIcon(pix);
//设置图标大小
this->setIconSize(QSize(pix.width(),pix.height()));
}
void myPushButton::zoom1()
{
//创建动态对象
QPropertyAnimation *pro =new QPropertyAnimation(this,"geometry");
//设置时间间隔
pro->setDuration(100);
//设置起始位置
pro->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
//设置结束位置
pro->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
//设置动态曲线
pro->setEasingCurve(QEasingCurve::OutBounce);
//开始移动
pro->start();
}
void myPushButton::zoom2()
{
//创建动态对象
QPropertyAnimation *pro =new QPropertyAnimation(this,"geometry");
//设置时间间隔
pro->setDuration(100);
//设置起始位置
pro->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
//设置结束位置
pro->setEndValue(QRect(this->x(),this->y(),this->width(),this->height()));
//设置动态曲线
pro->setEasingCurve(QEasingCurve::InBounce);
//开始移动
pro->start();
}
void myPushButton::mousePressEvent(QMouseEvent *event)
{
if(this->cIP!="")//按下的照片不为空 说明有按下状态 切换为按下图片
{
QPixmap pix;
pix.load(this->cIP);
//设置图片固定大小
this->setFixedSize(pix.width(),pix.height());
//设置不规则图片样式
this->setStyleSheet("QPushButton{border:0px};");
//设置图标
this->setIcon(pix);
//设置图标大小
this->setIconSize(QSize(pix.width(),pix.height()));
}
//让父类执行其他内容
return QPushButton::mousePressEvent(event);
}
void myPushButton::mouseReleaseEvent(QMouseEvent *event)
{
if(this->cIP!="")//按下的照片不为空 说明有按下状态 切换为初始图片
{
QPixmap pix;
pix.load(this->nIP);
//设置图片固定大小
this->setFixedSize(pix.width(),pix.height());
//设置不规则图片样式
this->setStyleSheet("QPushButton{border:0px};");
//设置图标
this->setIcon(pix);
//设置图标大小
this->setIconSize(QSize(pix.width(),pix.height()));
}
//让父类执行其他内容
return QPushButton::mouseReleaseEvent(event);
}