-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmypushbutton.cpp
69 lines (46 loc) · 1.47 KB
/
mypushbutton.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
#include "mypushbutton.h"
#include <QPixmap>
#include <QDebug>
#include <QPropertyAnimation>
//MyPushButton::MyPushButton(QWidget *parent)
// : QPushButton{parent}
//{
//}
MyPushButton::MyPushButton(QString normalImg, QString pressImg){
normalImgPath = normalImg;
pressImgPath = pressImg;
QPixmap pix;
bool ret = pix.load(normalImgPath);
if (!ret){
qDebug() << "Loading picture: " << normalImgPath << " failed. \n";
return;
}
// set fixed size of button
setFixedSize(pix.width(), pix.height());
// set style sheet of the button
setStyleSheet("QPushButton{border:0px}");
// set icon of the button
setIcon(pix);
// set icon size of the button
setIconSize(QSize(pix.width(), pix.height()));
}
void MyPushButton::zoom1(){
QPropertyAnimation* ani = new QPropertyAnimation(this, "geometry");
ani->setDuration(200);
// start value
ani->setStartValue(QRect(x(), y(), width(), height()));
// set end value
ani->setEndValue(QRect(x(), y() + 10, width(), height()));
ani->setEasingCurve(QEasingCurve::OutBounce);
ani->start();
}
void MyPushButton::zoom2(){
QPropertyAnimation* ani = new QPropertyAnimation(this, "geometry");
ani->setDuration(200);
// start value
ani->setStartValue(QRect(x(), y() + 10, width(), height()));
// set end value
ani->setEndValue(QRect(x(), y(), width(), height()));
ani->setEasingCurve(QEasingCurve::OutBounce);
ani->start();
}