-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectscene.cpp
More file actions
75 lines (59 loc) · 2.34 KB
/
selectscene.cpp
File metadata and controls
75 lines (59 loc) · 2.34 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
#include "selectscene.h"
selectScene::selectScene(QWidget *parent)
: MyMainWindow{parent}
{
MyPushButton *btnBackButton=new MyPushButton(":/res/BackButton.png",":/res/BackButtonSelected.png",this);
btnBackButton->resize(72,32);
btnBackButton->move(this->width()-btnBackButton->width(),this->height()-btnBackButton->height());
connect(btnBackButton,&QPushButton::clicked,this,&selectScene::backBtnClicked);
//信号可以连接信号
//设置行宽和列宽
int rowWidth=70;
int colWidth=70;
//设置x y 的偏移量 使关卡按钮偏移到想要的位置
int xOffset=25;
int yOffset=130;
for(int i=0;i<20;i++)
{
MyPushButton* btn=new MyPushButton("://res/LevelIcon.png","://res/LevelIcon.png",this);
btn->setText(QString::number(i+1));
int row=i/4;
int col=i%4;
int x=col*colWidth+xOffset;
int y=row*rowWidth+yOffset;
btn->resize(57,57);
btn->move(x,y);
//点击关卡按钮
connect(btn,&MyPushButton::clicked,[=](){
//设置按钮音效
QSoundEffect *sound=new QSoundEffect(this);
sound->setSource(QUrl::fromLocalFile(":/res/BackButtonSound.wav"));
sound->play();
playScene *playScene=new class playScene(i+1,this);
playScene->setAttribute(Qt::WA_DeleteOnClose);//关闭后窗口后释放开辟的内存
playScene->move(this->pos());//窗口对齐
this->hide();
playScene->show();
//当点击back按钮时 从playScene返回到selectScene
connect(playScene,&playScene::backBtnClicked,[=](){
//设置按钮音效
QSoundEffect *sound=new QSoundEffect(this);
sound->setSource(QUrl::fromLocalFile(":/res/BackButtonSound.wav"));
sound->play();
this->move(playScene->pos());
this->show();
playScene->close();
});
});
}
}
void selectScene::paintEvent(QPaintEvent *ev)
{
//绘制图片
QPainter painter(this);
painter.translate(0,this->menuBar()->height());//设置画家开始绘画的位置
QPixmap pix("://res/OtherSceneBg.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
pix.load("://res/Title.png");
painter.drawPixmap(0,0,pix);
}