代码拉取完成,页面将自动刷新
#include "keysetting.h"
#include "ui_keysetting.h"
#include <QPainter>
#include <QKeyEvent>
KeySetting::KeySetting(QWidget *parent)
: QWidget(parent), ui(new Ui::KeySetting) {
ui->setupUi(this);
this->setWindowModality(Qt::ApplicationModal);
this->setWindowTitle("按键设置");
qImg = new QImage(":/img/img/key.png");
}
KeySetting::~KeySetting() {
delete qImg;
delete ui;
}
void KeySetting::paintEvent(QPaintEvent *event) {
QPainter painter;
painter.begin(this);
painter.drawPixmap(QPoint(0, 0), QPixmap::fromImage(qImg->scaled(this->size() - QSize(0, this->size().height() / 2))));
painter.end();
Q_UNUSED(event);
}
void KeySetting::keyPressEvent(QKeyEvent *event) {
switch (event->key()) {
case Qt::Key_Period: {
ui->PushButtonA->setEnabled(false);
break;
}
case Qt::Key_Slash: {
ui->PushButtonB->setEnabled(false);
break;
}
case Qt::Key_Control: {
ui->PushButtonSelent->setEnabled(false);
break;
}
case Qt::Key_Return: {
ui->PushButtonEnter->setEnabled(false);
break;
}
case Qt::Key_W: {
ui->PushButtonUp->setEnabled(false);
break;
}
case Qt::Key_S: {
ui->PushButtonDown->setEnabled(false);
break;
}
case Qt::Key_A: {
ui->PushButtonLeft->setEnabled(false);
break;
}
case Qt::Key_D: {
ui->PushButtonRight->setEnabled(false);
break;
}
}
}
void KeySetting::keyReleaseEvent(QKeyEvent *event) {
switch (event->key()) {
case Qt::Key_Period: {
ui->PushButtonA->setEnabled(true);
break;
}
case Qt::Key_Slash: {
ui->PushButtonB->setEnabled(true);
break;
}
case Qt::Key_Control: {
ui->PushButtonSelent->setEnabled(true);
break;
}
case Qt::Key_Return: {
ui->PushButtonEnter->setEnabled(true);
break;
}
case Qt::Key_W: {
ui->PushButtonUp->setEnabled(true);
break;
}
case Qt::Key_S: {
ui->PushButtonDown->setEnabled(true);
break;
}
case Qt::Key_A: {
ui->PushButtonLeft->setEnabled(true);
break;
}
case Qt::Key_D: {
ui->PushButtonRight->setEnabled(true);
break;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。