Q:

Qt mainwindow handle space key press

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?

A:

uielement->setFocusPolicy(Qt::NoFocus); is one solution
or
QApplication::focusWidget() with some kind of clearFocus()

