问题
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