-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
52 lines (33 loc) · 1.07 KB
/
widget.cpp
File metadata and controls
52 lines (33 loc) · 1.07 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
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget{parent}
{
this->resize(600,600);
mazeArea = new Maze_Area(this);
startButton = new QPushButton("开始", this);
startButton->resize(200,200);
connect(startButton, &QPushButton::clicked, this, &Widget::onStartButtonClicked);
}
void Widget::onStartButtonClicked()
{
mazeArea->Request_Start_and_Execute(); // 调用迷宫区域的请求开始和执行方法
}
void Widget::paintEvent(QPaintEvent *event)
{
}
void Widget::resizeEvent(QResizeEvent *event)
{
int width = event->size().width();
int height = event->size().height();
mazeArea->resize(width - 200, height); // 调整迷宫区域大小
startButton->move(width - 200, 0); // 将按钮放在右侧
if (width< 200)
{
resize(200,height);
}
}
void Widget::keyPressEvent(QKeyEvent *event)
{
QWidget::keyPressEvent(event); // 调用基类处理其他键盘事件
// qDebug() << "按下的键:" << event->key(); // 输出按下的键
}