I have a widget and installed event filter to it,
{
qDebug("EventFilter type: %d", event->type());
int keyValue = ke->key();
if(event
->type
() == QEvent::KeyPress ) {
switch ( keyValue )
{
case Qt::Key_0: case Qt::Key_1: case Qt::Key_2: case Qt::Key_3 : case Qt::Key_4: case Qt::Key_5: case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: case Qt::Key_9 :
ListBoxA->numClicked((char *)ke->text().latin1());
break;
}
return true;
}
return false;
}
bool MyClass::eventFilter( QObject*, QEvent *event )
{
qDebug("EventFilter type: %d", event->type());
QKeyEvent *ke = (QKeyEvent *) event;
int keyValue = ke->key();
if(event->type() == QEvent::KeyPress )
{
switch ( keyValue )
{
case Qt::Key_0: case Qt::Key_1: case Qt::Key_2: case Qt::Key_3 : case Qt::Key_4: case Qt::Key_5: case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: case Qt::Key_9 :
ListBoxA->numClicked((char *)ke->text().latin1());
break;
}
return true;
}
return false;
}
To copy to clipboard, switch view to plain text mode
From the qDebug(), I found that the QEvent::KeyPress appear only once, that is, the first time I press a keyboard input. And all keyboard input afterward seems disappeared, no more can be received. However if I change it to QEvent::KeyRelease, I found that it works!
Can anyone tell me why is this happening? When will the KeyPress event occur? is it the eventFilter is not working or something else blocked the event?
QT4.6.3 used.
Thanks!
Bookmarks