-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamebutton.cpp
More file actions
52 lines (45 loc) · 1.36 KB
/
gamebutton.cpp
File metadata and controls
52 lines (45 loc) · 1.36 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
#include "gamebutton.h"
#include<QPushButton>
#include<QSound>
#define Button ":/resources/button.wav"
GameButton::GameButton(QString str,QString str2)
{
img1.load(str);
img2.load(str2);
this->setStyleSheet("QPushButton{border:0px;}");
this->setFixedSize(QSize(img1.width(),img1.height())); //按钮尺寸
this->setIcon(img1); //按钮图标
this->setIconSize(QSize(img1.width(),img1.height())); //图标尺寸
isRun = false;
}
GameButton::~GameButton()
{
}
void GameButton::init()
{
this->move(600,400);
}
void GameButton::mouseReleaseEvent(QMouseEvent *e)
{
//qDebug()<<"鼠标点击";
//isRun = true; //进入游戏
QSound::play(Button);
//this->move(this->x(),this->y()+25);
return QPushButton::mouseReleaseEvent(e);
}
void GameButton::enterEvent(QEvent *event)
{
//qDebug()<<"鼠标进入";
this->setFixedSize(QSize(img2.width(),img2.height())); //设置更大图标
this->setIcon(img2);
this->setIconSize(QSize(img2.width(),img2.height()));
this->move(this->x(),this->y()+20);
}
void GameButton::leaveEvent(QEvent *event)
{
//qDebug()<<"鼠标离开";
this->setFixedSize(QSize(img1.width(),img1.height())); //按钮尺寸
this->setIcon(img1); //按钮图标
this->setIconSize(QSize(img1.width(),img1.height())); //图标尺寸
this->move(this->x(),this->y()-20);
}