Results 1 to 7 of 7

Thread: How to remove default 'ENTER' from QDialogButtonBox

  1. #1
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default How to remove default 'ENTER' from QDialogButtonBox

    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 ...

    Qt Code:
    1. BasicDataDialog::BasicDataDialog(QWidget *parent)
    2. : QDialog(parent)
    3. {
    4. ui.setupUi(this);
    5. ui.buttonBox->button(QDialogButtonBox::Ok)->setDefault(false);
    6. ui.buttonBox->button(QDialogButtonBox::Cancel)->setDefault(false);
    7. ui.buttonBox->button(QDialogButtonBox::Ok)->setAutoDefault(false);
    8. ui.buttonBox->button(QDialogButtonBox::Cancel)->setAutoDefault(false);
    To copy to clipboard, switch view to plain text mode 

    .. but it did not work.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to remove default 'ENTER' from QDialogButtonBox

    Maybe you should do it in the reverse order?
    Qt Code:
    1. ui.buttonBox->button(QDialogButtonBox::Ok)->setAutoDefault(false);
    2. ui.buttonBox->button(QDialogButtonBox::Cancel)->setAutoDefault(false);
    3. ui.buttonBox->button(QDialogButtonBox::Ok)->setDefault(false);
    4. ui.buttonBox->button(QDialogButtonBox::Cancel)->setDefault(false);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: How to remove default 'ENTER' from QDialogButtonBox

    thx, but does not work ...

  4. #4
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: How to remove default 'ENTER' from QDialogButtonBox

    I replaced the buttonBox with ordinary pushButtons ...

  5. #5
    Join Date
    May 2008
    Posts
    58
    Thanks
    2

    Default Re: How to remove default 'ENTER' from QDialogButtonBox

    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.

  6. #6
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: How to remove default 'ENTER' from QDialogButtonBox

    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to remove default 'ENTER' from QDialogButtonBox

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.