What is the difference between autodefault and default in Qpushbutton?

  • I have read the qt doc. but not clear about that.

  • This is the key part in the [[doc:QPushButton]] docs:

    [quote]A button with this property set to true (i.e., the dialog's default button,) will automatically be pressed when the u
    ser presses enter, with one exception: if an autoDefault button currently has focus, the autoDefault button is pressed. When the dialog has autoDefault buttons but no default button, pressing enter will press either the autoDefault button that currently has focus, or if no button has focus, the next autoDefault button in the focus chain.

    In a dialog, only one push button at a time can be the default button. This button is then displayed with an additional frame (depending on the GUI style).[/quote]

    Buttons that have a QDialog as a parent, are autodefault by default.

  • Did you mean autodefault button respond to enter key and it is default in case of QDialog as parent

  • [quote author="pratik041" date="1320735323"]Did you mean autodefault button respond to enter key and it is default in case of QDialog as parent[/quote]

    Autodefault button respond to enter if they have focus, otherwise the default button is pressed. If you don't have the default button, the first autodefault will be pressed.

  • Hi all,

    At least in Qt 4.8.2, the QPushButton default/autoDefault behaviours don’t seem to reflect the documentation nor what is stated above. Actually I can’t get an OK button that will be pressed upon Enter when it does not have the focus.

    QPushButton *okButton = new QPushButton(tr("OK"), this);
    QPushButton *cancelButton = new QPushButton(tr("Cancel"), this);
    QPushButton *applyButton = new QPushButton(tr("Appl&y"), this);

    By selecting the Apply button before hitting Enter, It is easy to check that the above code does not produce the desired effect: the dialog remains open.

    Setting instead

    does not help.


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.