PDA

View Full Version : How to remove default 'ENTER' from QDialogButtonBox



janus
11th September 2008, 17:40
Hi,

I have a Dialog with a QDialogButtonBox and would like to remove the default button behavior i.e. when I press 'enter' the Dialog is closed. I tried this ...


BasicDataDialog::BasicDataDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
ui.buttonBox->button(QDialogButtonBox::Ok)->setDefault(false);
ui.buttonBox->button(QDialogButtonBox::Cancel)->setDefault(false);
ui.buttonBox->button(QDialogButtonBox::Ok)->setAutoDefault(false);
ui.buttonBox->button(QDialogButtonBox::Cancel)->setAutoDefault(false);

.. but it did not work. :confused:

jacek
11th September 2008, 18:24
Maybe you should do it in the reverse order?

ui.buttonBox->button(QDialogButtonBox::Ok)->setAutoDefault(false);
ui.buttonBox->button(QDialogButtonBox::Cancel)->setAutoDefault(false);
ui.buttonBox->button(QDialogButtonBox::Ok)->setDefault(false);
ui.buttonBox->button(QDialogButtonBox::Cancel)->setDefault(false);

janus
11th September 2008, 18:49
thx, but does not work ...

janus
11th September 2008, 21:13
I replaced the buttonBox with ordinary pushButtons ...

yxmaomao
12th September 2008, 06:08
how did you do?
I create one app based on dialog with Qt wizard in Visual Studio 2005
I can't find the question you mentioned.

janus
12th September 2008, 09:39
Hi,
I don't really understand what you mean ... . I seems that if you don't want the autoDefault behavior you just add pushButtons and connect them to the accept/reject slots instead of using the QDialogButtonBox.

jacek
12th September 2008, 21:56
The docs suggest that you can invoke setDefault() and setAutoDefault() on buttons and then add them to the QDialogButtonBox. See the example in the docs. This way you get rid of a default button and still have the button box.