|  | Home · Overviews · Examples |

# QDialogButtonBox Class Reference
[com.trolltech.qt.gui module]

The `QDialogButtonBox` class is a widget that presents buttons in a layout that is appropriate to the current widget style. More...

Inherits `QWidget`.

## Detailed Description

The `QDialogButtonBox` class is a widget that presents buttons in a layout that is appropriate to the current widget style.

Dialogs and message boxes typically present buttons in a layout that conforms to the interface guidelines for that platform. Invariably, different platforms have different layouts for their dialogs. `QDialogButtonBox` allows a developer to add buttons to it and will automatically use the appropriate layout for the user's desktop environment.

Most buttons for a dialog follow certain roles. Such roles include:

- Accepting or rejecting the dialog.
- Asking for help.
- Performing actions on the dialog itself (such as resetting fields or applying changes).

There can also be alternate ways of dismissing the dialog which may cause destructive results.

Most dialogs have buttons that can almost be considered standard (e.g. OK and Cancel buttons). It is sometimes convenient to create these buttons in a standard way.

There are a couple ways of using `QDialogButtonBox`. One ways is to create the buttons (or button texts) yourself and add them to the button box, specifying their role.

            findButton = new QPushButton(tr("&Find"));
            findButton->setDefault(true);

            moreButton = new QPushButton(tr("&More"));
            moreButton->setCheckable(true);
            moreButton->setAutoDefault(false);

            buttonBox = new QDialogButtonBox(Qt::Vertical);
            buttonBox->addButton(findButton, QDialogButtonBox::ActionRole);
            buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);

Alternatively, `QDialogButtonBox` provides several standard buttons (e.g. OK, Cancel, Save) that you can use. They exist as flags so you can OR them together in the constructor.

            buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                             | QDialogButtonBox::Cancel);

            connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
            connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

You can mix and match normal buttons and standard buttons.

Currently the buttons are laid out in the following way if the button box is horizontal:

| Button box laid out in horizontal `GnomeLayout`
| Button box laid out in horizontal `KdeLayout`
| Button box laid out in horizontal `MacLayout`
| Button box laid out in horizontal `WinLayout`

The buttons are laid out the following way if the button box is vertical:

| Button box laid out in vertical `GnomeLayout`
| Button box laid out in vertical `KdeLayout`
| Button box laid out in vertical `MacLayout`
| Button box laid out in vertical `WinLayout`

Additionally, button boxes that contain only buttons with `ActionRole` or `HelpRole` can be considered modeless and have an alternate look on the mac:

| modeless horizontal `MacLayout`
| modeless vertical `MacLayout`

When a button is clicked in the button box, the `clicked` signal is emitted for the actual button is that is pressed. For convenience, if the button has an `AcceptRole`, `RejectRole`, or `HelpRole`, the `accepted`, `rejected`, or `helpRequested` signals are emitted respectively.

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,

See also `QMessageBox`, `QPushButton`, and `QDialog`.