Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is the difference between autodefault and default in Qpushbutton?
Forum Updated to NodeBB v4.3 + New Features

What is the difference between autodefault and default in Qpushbutton?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 11.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

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

    Pratik Agrawal

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #3

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

        Pratik Agrawal

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Alexandre Oberlin
            wrote on last edited by
            #5

            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.

            Example
            @
            QPushButton *okButton = new QPushButton(tr("OK"), this);
            okButton->setDefault(true);
            okButton->setAutoDefault(false);
            QPushButton *cancelButton = new QPushButton(tr("Cancel"), this);
            cancelButton->setAutoDefault(false);
            QPushButton *applyButton = new QPushButton(tr("Appl&y"), this);
            applyButton->setAutoDefault(false);
            @

            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
            @okButton->setAutoDefault(true);@

            does not help.

            Alexandre

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved