I am trying to capture the keypress event in a QDialog.
In my constructor, I have this as the last line:
QObject::installEventFilter(this);
Then I have this method:
{
if(event
->type
() == QEvent::KeyPress){ keyEvent = static_cast<QKeyEvent *>(event);
}
else{
return QObject::eventFilter(obj, event
);
}
if(keyEvent->isAutoRepeat()){
return QObject::eventFilter(obj, event
);
}
if(keyEvent->key() == Qt::Key_1){
keyEvent->accept();
this->close();
return true;
}
else{
return QObject::eventFilter(obj, event
);
}
}
bool frmFileDialog::eventFilter(QObject *obj, QEvent *event)
{
QKeyEvent *keyEvent;
if(event->type() == QEvent::KeyPress){
keyEvent = static_cast<QKeyEvent *>(event);
}
else{
return QObject::eventFilter(obj, event);
}
if(keyEvent->isAutoRepeat()){
return QObject::eventFilter(obj, event);
}
if(keyEvent->key() == Qt::Key_1){
keyEvent->accept();
this->close();
return true;
}
else{
return QObject::eventFilter(obj, event);
}
}
To copy to clipboard, switch view to plain text mode
The issue I am having is if any of regular keys are typed on the keyboard (i.e. the 1 key), the method is not entered at all. If "F1" or the tab key are pressed, it is entered. What do I need to capture any key that is pressed in this Dialog?
Thanks,
Kevin
Bookmarks