PDA

View Full Version : Problem with KeyPressEvent



sali555
24th April 2011, 13:48
Hi,
I have a problem with the event for Key_Space:
my code:

void MainWindow::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Space: // THIS DOESNT WORK
qDebug() << "space";
break;

case Qt::Key_A: // THIS WORKS FINE
qDebug() << "A";
break;
default:
QWidget::keyPressEvent(event);
break;
}
}

Do you know where is the mistake. Thx

squidge
24th April 2011, 15:01
Space is typically used to select a control (like clicking it with the mouse). The tab key will act similarly.

rsilva
24th April 2011, 15:08
You can try to installEventFilter and get the space key with it instead of keyPressEvent but I don't know if it's called before or after the Key_Space processing for the controls like squidge said