32 lines
1.1 KiB
C++
32 lines
1.1 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
ui->setupUi(this);
|
|
}
|
|
|
|
MainWindow::~MainWindow() { delete ui; }
|
|
|
|
void MainWindow::keyPressEvent(QKeyEvent *event) {
|
|
if (event->key() == Qt::Key_Up) {
|
|
ui->l->move(ui->l->pos().x(), ui->l->pos().y() - 20);
|
|
} else if (event->key() == Qt::Key_Down) {
|
|
ui->l->move(ui->l->pos().x(), ui->l->pos().y() + 20);
|
|
} else if (event->key() == Qt::Key_Left) {
|
|
ui->l->move(ui->l->pos().x() - 20, ui->l->pos().y());
|
|
} else if (event->key() == Qt::Key_Right) {
|
|
ui->l->move(ui->l->pos().x() + 20, ui->l->pos().y());
|
|
}
|
|
}
|
|
void MainWindow::keyReleaseEvent(QKeyEvent *e) {
|
|
if (e->key() == Qt::Key_Up) {
|
|
ui->l->move(ui->l->pos().x(), ui->l->pos().y() - 20);
|
|
} else if (e->key() == Qt::Key_Down) {
|
|
ui->l->move(ui->l->pos().x(), ui->l->pos().y() + 20);
|
|
} else if (e->key() == Qt::Key_Left) {
|
|
ui->l->move(ui->l->pos().x() - 20, ui->l->pos().y());
|
|
} else if (e->key() == Qt::Key_Right) {
|
|
ui->l->move(ui->l->pos().x() + 20, ui->l->pos().y());
|
|
}
|
|
}
|