CustomerInfoDialog::CustomerInfoDialog(QWidget *parent) : QDialog(parent){ ... firstNameEdit->installEventFilter(this); lastNameEdit->installEventFilter(this); cityEdit->installEventFilter(this); phoneNumberEdit->installEventFilter(this);}
bool CustomerInfoDialog::eventFilter(QObject *target, QEvent *event){ if (target == firstNameEdit || target == lastNameEdit || target == cityEdit || target == phoneNumberEdit) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); if (keyEvent->key() == Qt::Key_Space) { focusNextChild(); return true; } } } return QDialog::eventFilter(target, event);}
... if (keyEvent->key() == Qt::Key_Space) ...
Qt::Key_Return
if (keyEvent->key() == Qt::Key_Return || keyEvent->key()==Qt::Key_Enter) { focusNextChild(); return true;}