Qt mainwindow handle space key press

跟風遠走 提交于 2019-12-12 06:23:16

问题


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.

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?


回答1:


uielement->setFocusPolicy(Qt::NoFocus); is one solution

or

QApplication::focusWidget() with some kind of clearFocus()



来源:https://stackoverflow.com/questions/18242065/qt-mainwindow-handle-space-key-press

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!