Qt即时响应来自keybaord的按键
Qt instant response to a pressed key from keybaord
我正在尝试用键盘上的箭头键向左或向右移动摇杆。下面的这段代码可以一步一步地完成,我的意思是,无论我握着键盘上的向左箭头还是只是点击它,摇杆只能移动 5 个单位。我想做的是只要我握着钥匙就移动它。
bool handled = false;
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent *keyEvent = (QKeyEvent *)e;
if ( keyEvent->key() == Qt::Key_Left )
{
left= (= == 0 ? -5 : 0);
handled = true;
}
else if ( keyEvent->key() == Qt::Key_Right )
{
right= (right== 0 ? 5 : 0);
handled = true;
}
}
我在 QKeyEvent 类中找不到适用于我想做的事情的方法。我该如何解决这个问题?
你为什么不使用 QAction?例如,捕捉左键按下:
QAction *action = new QAction("test", this);
action->setShortcut(QKeySequence("Left"));
this->addAction(action);
this->connect(action, SIGNAL(triggered()), this, SLOT(left_button_slot()));
和一个插槽
void Widget::left_button_slot()
{
//do whatever you want
QMessageBox::information(this, "Hey", "You pressed left key !");
}
相关文章:
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- C++ 信号和插槽不工作:插槽不响应事件
- NodeJs 服务器充斥着 UDP 广播,不发送响应
- C++关于ENUM的问题。我得到的响应比枚举列表大
- 应用程序在打开的简历中捕获视频后没有响应
- 使用 cpprest (Casablanca) 返回 PDF 响应
- 为什么当通过 TCP 发送的消息速率增加时,请求-响应消息对的延迟会降低?
- 如何使用从处理程序调度的最终回调将响应异步返回给调用方on_read?
- 获取加密的正文响应WinHttp HTTPS
- QtConcurrent - 在发布到 UI 线程的数千个结果中保持 GUI 响应
- 同步读取多个 TCP 响应
- HTTP 响应格式不正确?
- 如何使用软化工具包从 OPC UA 服务器异步读取操作回调中的数据值响应中获取 NodeId 详细信息
- HTTP帖子,无需等待响应
- 问题导致程序停止响应,并且姓氏未正确打印
- AT 命令响应解析器
- 将静态 IP 分配给我的 ESP32 服务器后不再响应
- 用于C++的 TCP/IP 解析器和响应器
- 我会导致太多内存泄漏,以至于我的计算机无响应吗?
- Qt即时响应来自keybaord的按键