Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66109

QDialogButtonBox selects buttons wiithout accept role as default

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.10.0
    • None
    • * Archlinux
       * {{QT 5.10}}

    Description

      QDialogButtonBox says in it's documentation:

      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,

      But that's not the case. If you add only a cancel button (which has the reject role), it will be the default button.

      I created an example, by using the ConfigDialog example. Therefore I added two lines in line 90 of configdialog.cpp:

      QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, this);
      connect(buttons, &QDialogButtonBox::rejected, this, &QWidget::close);

      If you start the example and press enter, the dialog closes because of the cancel button.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            davidk David Kahles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes