-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmypushbutton.cpp
More file actions
100 lines (74 loc) · 2.6 KB
/
mypushbutton.cpp
File metadata and controls
100 lines (74 loc) · 2.6 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
96
97
98
99
100
#include "mypushbutton.h"
#include <QDebug>
#include <QPixmap>
#include <QPropertyAnimation>
MyPushButton::MyPushButton(QString normarlImg, QString pressImg)
{
this->normarlImgPath = normarlImg;
this->pressImgPath = pressImg;
QPixmap pix;
bool ret = pix.load(normarlImgPath);
if(!ret){
QString str = QString("We can not load image!").arg(normarlImg);
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 * animation = new QPropertyAnimation(this, "geometry");
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(QAbstractAnimation::DeleteWhenStopped);
}
void MyPushButton::zoom2()
{
QPropertyAnimation * animation = new QPropertyAnimation(this, "geometry");
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(QAbstractAnimation::DeleteWhenStopped);
}
void MyPushButton::mousePressEvent(QMouseEvent * e)
{
if(this->pressImgPath != "")
{
QPixmap pix;
bool ret = pix.load(pressImgPath);
if(!ret){
QString str = QString("We can not load image!").arg(this->pressImgPath);
qDebug() << "";
return;
}
this->setFixedSize(pix.width(), pix.height());
this->setStyleSheet("QPushButton{border: 0px;}");
this->setIcon(pix);
this->setIconSize(QSize(pix.width(), pix.height()));
}
QPushButton::mousePressEvent(e);
}
void MyPushButton::mouseReleaseEvent(QMouseEvent * e)
{
if(this->pressImgPath != "")
{
QPixmap pix;
bool ret = pix.load(normarlImgPath);
if(!ret){
QString str = QString("We can not load image!").arg(this->normarlImgPath);
qDebug() << "";
return;
}
this->setFixedSize(pix.width(), pix.height());
this->setStyleSheet("QPushButton{border: 0px;}");
this->setIcon(pix);
this->setIconSize(QSize(pix.width(), pix.height()));
}
QPushButton::mouseReleaseEvent(e);
}