-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmybutton.cpp
More file actions
31 lines (27 loc) · 1.21 KB
/
mybutton.cpp
File metadata and controls
31 lines (27 loc) · 1.21 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
#include "mybutton.h"
#include <QPixmap>
#include <QPropertyAnimation>
MyButton::MyButton(QString pix) : QPushButton(0)
{
QPixmap pixmap(pix);
this->setFixedSize(pixmap.width(),pixmap.height());//设置按钮大小
this->setStyleSheet("QPushButton{border:Opx;}");
this->setIcon(pixmap);//传入图片
this->setIconSize(QSize(pixmap.width(),pixmap.height()));//图片大小和按钮大小保持一致
}
void MyButton::down(){
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();//执行
}
void MyButton::up(){
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();
}