Qt主窗口句柄空格键按下 [英] Qt mainwindow handle space key press

查看:675
本文介绍了Qt主窗口句柄空格键按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Qt程序,我想在用户按下Space时被触发,但是它不起作用.

I am programming a Qt programm and I want to get triggered, when the user presses Space, but it doesn't work.

mainwindow.h

protected:
    void keyPressEvent(QKeyEvent* event);

mainwindow.m

void MainWindow::keyPressEvent(QKeyEvent* event) {
    qDebug() << event->key();
}

除空格外,几乎所有键都在起作用.

Nearly every key is working, except for the space.

该空间是否有可能无法使用,因为某个UI元素有一些焦点,如果是,我该如何解决呢?

Could it be possible that the space isn't working, because there is some focus to an UI Element, if yes, how can I fix it?

推荐答案

uielement->setFocusPolicy(Qt::NoFocus);是一种解决方案

QApplication::focusWidget()和某种clearFocus()

这篇关于Qt主窗口句柄空格键按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆