QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog
Hello,
I am not quite sure about that, but it seems that, the QDialogButtonBox always causes that the OK button is "clicked" when the Enter button is pressed in the dialog.
The setDefault and setAutoDefault for contained buttons seems not to work.
Could anybody confirm this behavior? How to prevent this.
I'd like that the pressing of the Enter button causes, that the cursor moves to the next field.
Thx
Re: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog
For me it works fine.
The Enter press is caught only when the ButtonBox has the focus.
Re: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog
Quote:
Originally Posted by
mcosta
For me it works fine.
The Enter press is caught only when the ButtonBox has the focus.
I am pressing Enter when I finish editing in QLineEdit ==> QLineEdit has focus, though
the OK ButtonBox sends the clicked() signal
Re: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog
It's true and it's a features of QDialog.
To avoid it you have to reimplement QDialog::keyPressEventIn example
Code:
{
switch (e->key ()) {
case Qt::Key_Return:
case Qt::Key_Enter:
qDebug ("Return/enter pressed");
// Do your work
break;
default:
}
}
Re: QDialogButtonBox causes OK button "clicked", when Enter pressed in dialog
Thanks for the answer.
I think I've found the more simple solution. That's only QDialogButtonBox that reacts in this way on Enter button. When instead of of it I use separate QPushButtons everything works perfect.