6.0.0-rc4Source

QDialogButtonBox Class

The QDialogButtonBox class lays out the buttons of a dialog in the order of the platform. More…

Header#include <QDialogButtonBox>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget

List of all members, including inherited members

Public Types

Public Functions

QDialogButtonBox(QWidget *parent = nullptr)
QDialogButtonBox(Qt::Orientation orientation, QWidget *parent = nullptr)
QDialogButtonBox(StandardButtons buttons, QWidget *parent = nullptr)
QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation, QWidget *parent = nullptr)
~QDialogButtonBox()
voidsetOrientation(Qt::Orientation orientation)
Qt::Orientationorientation() const
voidaddButton(QAbstractButton *button, ButtonRole role)
QPushButton *addButton(const QString &text, ButtonRole role)
QPushButton *addButton(StandardButton button)
voidremoveButton(QAbstractButton *button)
voidclear()
QList<QAbstractButton *>buttons() const
ButtonRolebuttonRole(QAbstractButton *button) const
voidsetStandardButtons(StandardButtons buttons)
StandardButtonsstandardButtons() const
StandardButtonstandardButton(QAbstractButton *button) const
QPushButton *button(StandardButton which) const
voidsetCenterButtons(bool center)
boolcenterButtons() const

Signals

voidclicked(QAbstractButton *button)
voidaccepted()
voidhelpRequested()
voidrejected()

Reimplemented Protected Functions

voidshowEvent(QShowEvent *event)

Detailed Description

A button box holds the buttons of a dialog, such as OK and Cancel, and puts them in the order that the desktop uses, whatever order they were added in. Each button has a role, and the box emits accepted(), rejected() or helpRequested() when a button of an accepting, rejecting or help role is clicked:

auto *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dialog);
connect(buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject);

Standard buttons come with their text and role. Other buttons are added with addButton() and a role. In a QDialog the first button with the AcceptRole becomes the default button when the box is shown, unless the dialog already has one.

See also QDialog and QMessageBox.

Differences from Qt

The buttons are always in the KDE order of Qt: help and reset buttons at the start, then a stretch, then the yes, no, action, accept, apply, destructive and reject buttons. The texts of the standard buttons have no mnemonics and are not translated, and the buttons have no icons. AlternateRole is not used.

Member Type Documentation

enum QDialogButtonBox::ButtonLayout

The orders of buttons of the desktops that Qt knows.

ConstantDescription
QDialogButtonBox::WinLayoutWindows.
QDialogButtonBox::MacLayoutmacOS.
QDialogButtonBox::KdeLayoutKDE, the order that Nt uses.
QDialogButtonBox::GnomeLayoutGNOME.
QDialogButtonBox::AndroidLayoutAndroid.

enum QDialogButtonBox::ButtonRole

The role of a button, which says where it goes and what clicking it means.

ConstantDescription
QDialogButtonBox::InvalidRoleNot a valid role.
QDialogButtonBox::AcceptRoleAccepts the dialog, such as OK.
QDialogButtonBox::RejectRoleRejects the dialog, such as Cancel.
QDialogButtonBox::DestructiveRoleThrows changes away and closes the dialog, such as Discard.
QDialogButtonBox::ActionRoleDoes something in the dialog without closing it.
QDialogButtonBox::HelpRoleAsks for help.
QDialogButtonBox::YesRoleA Yes button.
QDialogButtonBox::NoRoleA No button.
QDialogButtonBox::ResetRoleResets the fields of the dialog to their defaults.
QDialogButtonBox::ApplyRoleApplies the changes without closing the dialog.

enum QDialogButtonBox::StandardButton

The standard buttons, each with its text and role. StandardButtons is a typedef for QFlags<StandardButton>.

ConstantDescription
QDialogButtonBox::NoButtonNo button.
QDialogButtonBox::OkOK, with the AcceptRole.
QDialogButtonBox::SaveSave, with the AcceptRole.
QDialogButtonBox::SaveAllSave All, with the AcceptRole.
QDialogButtonBox::OpenOpen, with the AcceptRole.
QDialogButtonBox::YesYes, with the YesRole.
QDialogButtonBox::YesToAllYes to All, with the YesRole.
QDialogButtonBox::NoNo, with the NoRole.
QDialogButtonBox::NoToAllNo to All, with the NoRole.
QDialogButtonBox::AbortAbort, with the RejectRole.
QDialogButtonBox::RetryRetry, with the AcceptRole.
QDialogButtonBox::IgnoreIgnore, with the AcceptRole.
QDialogButtonBox::CloseClose, with the RejectRole.
QDialogButtonBox::CancelCancel, with the RejectRole.
QDialogButtonBox::DiscardDiscard, with the DestructiveRole.
QDialogButtonBox::HelpHelp, with the HelpRole.
QDialogButtonBox::ApplyApply, with the ApplyRole.
QDialogButtonBox::ResetReset, with the ResetRole.
QDialogButtonBox::RestoreDefaultsRestore Defaults, with the ResetRole.

typedef QDialogButtonBox::StandardButtons

The StandardButtons type is a typedef for QFlags<StandardButton>. It stores an OR combination of StandardButton values.

Member Function Documentation

[explicit] QDialogButtonBox::QDialogButtonBox(QWidget *parent = nullptr)

Constructs an empty horizontal button box with the given parent.

[explicit] QDialogButtonBox::QDialogButtonBox(Qt::Orientation orientation, QWidget *parent = nullptr)

Constructs an empty button box with the given orientation and parent.

[explicit] QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, QWidget *parent = nullptr)

Constructs a horizontal button box with the standard buttons and the given parent.

QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation, QWidget *parent = nullptr)

Constructs a button box with the standard buttons, the given orientation and parent.

[override] QDialogButtonBox::~QDialogButtonBox()

Destroys the button box and its buttons.

[signal] void QDialogButtonBox::accepted()

This signal is emitted when a button with the AcceptRole or the YesRole is clicked.

void QDialogButtonBox::addButton(QAbstractButton *button, ButtonRole role)

Adds button to the box with the given role. The box takes the button as a child. A button with the InvalidRole is not added.

See also removeButton().

QPushButton * QDialogButtonBox::addButton(const QString &text, ButtonRole role)

This is an overloaded function.

Creates a push button with the given text and role, adds it, and returns it.

QPushButton * QDialogButtonBox::addButton(StandardButton button)

This is an overloaded function.

Adds the standard button, unless the box has it already, and returns it.

QPushButton * QDialogButtonBox::button(StandardButton which) const

Returns the push button of the standard button which, or nullptr if the box does not have it.

See also standardButton().

ButtonRole QDialogButtonBox::buttonRole(QAbstractButton *button) const

Returns the role of button, or InvalidRole if it is not in the box.

QList<QAbstractButton *> QDialogButtonBox::buttons() const

Returns the buttons of the box, in the order they were added.

bool QDialogButtonBox::centerButtons() const

Returns whether the buttons are centered in the box. The default is false.

See also setCenterButtons().

void QDialogButtonBox::clear()

Deletes all the buttons of the box.

See also removeButton().

[signal] void QDialogButtonBox::clicked(QAbstractButton *button)

This signal is emitted when button of the box is clicked, before accepted(), rejected() or helpRequested().

[signal] void QDialogButtonBox::helpRequested()

This signal is emitted when a button with the HelpRole is clicked.

Qt::Orientation QDialogButtonBox::orientation() const

Returns the direction the buttons are laid out in, Qt::Horizontal by default.

See also setOrientation().

[signal] void QDialogButtonBox::rejected()

This signal is emitted when a button with the RejectRole or the NoRole is clicked.

void QDialogButtonBox::removeButton(QAbstractButton *button)

Removes button from the box without deleting it; the button no longer has a parent.

See also addButton() and clear().

void QDialogButtonBox::setCenterButtons(bool center)

Sets whether the buttons are centered in the box, rather than in the order of the platform with a stretch between the groups, to center.

See also centerButtons().

void QDialogButtonBox::setOrientation(Qt::Orientation orientation)

Sets the direction the buttons are laid out in to orientation.

See also orientation().

void QDialogButtonBox::setStandardButtons(StandardButtons buttons)

Makes the standard buttons of the box buttons: the standard buttons it has are deleted, and the ones in buttons are created. Buttons that are not standard stay.

See also standardButtons().

[override, protected] void QDialogButtonBox::showEvent(QShowEvent *event)

Reimplements QWidget::showEvent().

In a QDialog without a default button, the first push button with the AcceptRole or the YesRole becomes the default.

StandardButton QDialogButtonBox::standardButton(QAbstractButton *button) const

Returns which standard button button is, or NoButton if it is not a standard button of the box.

See also button().

StandardButtons QDialogButtonBox::standardButtons() const

Returns the standard buttons of the box.

See also setStandardButtons().