Sorry JD2000, I probably didn't state the problem clearly.
The pushbutton works fine. I just want it clicked when the Enter key is hit.
This is automatic on the default button in a dialog, but not a mainwindow.
Here is what I have tried but it does nothing:
ui->pbSave->installEventFilter(this);
{
if (object
== ui
->pbSave
&& event
->type
() == QEvent::KeyPress) { QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
if (keyEvent->key() == Qt::Key_Enter) {
ui->pbSave->click();
return true;
} else
return false;
}
return false;
}
ui->pbSave->installEventFilter(this);
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
if (object == ui->pbSave && event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Enter) {
ui->pbSave->click();
return true;
} else
return false;
}
return false;
}
To copy to clipboard, switch view to plain text mode
I am probably not understanding the event filter doc correctly.
Any help appreciated.
Bookmarks