2 Star 5 Fork 1

Quard/game_box

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
keysetting.cpp 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
Quard 提交于 2022-07-20 17:45 . src:porting to qt6 version qt multimedia
#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;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/QQxiaoming/game_box.git
git@gitee.com:QQxiaoming/game_box.git
QQxiaoming
game_box
game_box
main

搜索帮助