1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3
4 MainWindow::MainWindow(QWidget *parent) :
5 QMainWindow(parent),
6 ui(new Ui::MainWindow)
7 {
8 ui->setupUi(this);
9 }
10
11 MainWindow::~MainWindow()
12 {
13 delete ui;
14 }
15
16 void MainWindow::keyPressEvent(QKeyEvent *event)
17 {
18 int x = ui->pushButton->x();
19 int y = ui->pushButton->y();
20 switch (event->key()) {
21 case Qt::Key_A:
22 ui->pushButton->move(x-10,y);
23 break;
24 case Qt::Key_D:
25 ui->pushButton->move(x+10,y);
26 break;
27 case Qt::Key_W:
28 ui->pushButton->move(x,y-10);
29 break;
30 case Qt::Key_S:
31 ui->pushButton->move(x,y+10);
32 break;
33 default:
34 break;
35 }
36 }