How to make a button the default?
Solved
General and Desktop
-
I have this code:
QPushButton* closeButton = new QPushButton(tr("&Close")); QPushButton* revertButton = new QPushButton(tr("&Revert")); QPushButton* submitButton = new QPushButton(tr("&Submit")); closeButton->setDefault(true); connect(closeButton, &QPushButton::clicked, this, &PasswordDetailsDlg::close); connect(revertButton, &QPushButton::clicked, this, &PasswordDetailsDlg::revert); connect(submitButton, &QPushButton::clicked, this, &PasswordDetailsDlg::submit); QDialogButtonBox* buttonBox = new QDialogButtonBox; buttonBox->addButton(submitButton, QDialogButtonBox::ResetRole); buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole); buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole); return buttonBox;
The close button should be the default and have the focus but it isn't!! Why??
-
Hi,
What if you set autoDefault as well ?
-
If you want a specific button to be default you need to call QPushButton::setDefault() on it yourself. However, if there is no default button set and to preserve which button is the default button across platforms when using the QPushButton::autoDefault property, the first push button with the accept role is made the default button when the QDialogButtonBox is shown,
-