Table of Contents
- QDialogButtonBox
- Synopsis
- Detailed Description
PySide2.QtWidgets.QDialogButtonBoxPySide2.QtWidgets.QDialogButtonBox.ButtonRolePySide2.QtWidgets.QDialogButtonBox.StandardButtonPySide2.QtWidgets.QDialogButtonBox.ButtonLayoutPySide2.QtWidgets.QDialogButtonBox.accepted()PySide2.QtWidgets.QDialogButtonBox.addButton()PySide2.QtWidgets.QDialogButtonBox.button()PySide2.QtWidgets.QDialogButtonBox.buttonRole()PySide2.QtWidgets.QDialogButtonBox.buttons()PySide2.QtWidgets.QDialogButtonBox.centerButtons()PySide2.QtWidgets.QDialogButtonBox.clear()PySide2.QtWidgets.QDialogButtonBox.clicked()PySide2.QtWidgets.QDialogButtonBox.helpRequested()PySide2.QtWidgets.QDialogButtonBox.orientation()PySide2.QtWidgets.QDialogButtonBox.rejected()PySide2.QtWidgets.QDialogButtonBox.removeButton()PySide2.QtWidgets.QDialogButtonBox.setCenterButtons()PySide2.QtWidgets.QDialogButtonBox.setOrientation()PySide2.QtWidgets.QDialogButtonBox.setStandardButtons()PySide2.QtWidgets.QDialogButtonBox.standardButton()PySide2.QtWidgets.QDialogButtonBox.standardButtons()
Previous topic
Next topic
Quick search
QDialogButtonBox露
The
QDialogButtonBoxclass is a widget that presents buttons in a layout that is appropriate to the current widget style. More鈥

Synopsis露
Functions露
def
addButton(button)def
addButton(button, role)def
addButton(text, role)def
button(which)def
buttonRole(button)def
buttons()def
centerButtons()def
clear()def
orientation()def
removeButton(button)def
setCenterButtons(center)def
setOrientation(orientation)def
setStandardButtons(buttons)def
standardButton(button)def
standardButtons()
Signals露
def
accepted()def
clicked(button)def
helpRequested()def
rejected()
Detailed Description露
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.
QDialogButtonBoxallows a developer to add buttons to it and will automatically use the appropriate layout for the user鈥檚 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 = QPushButton(self.tr("&Find")) findButton.setDefault(True) moreButton = QPushButton(self.tr("&More")) moreButton.setCheckable(True) moreButton.setAutoDefault(False) buttonBox = QDialogButtonBox(Qt.Vertical) buttonBox.addButton(findButton, QDialogButtonBox.ActionRole) buttonBox.addButton(moreButton, QDialogButtonBox.ActionRole)Alternatively,
QDialogButtonBoxprovides 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.self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.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
WinLayoutThe buttons are laid out the following way if the button box is vertical:
GnomeLayout
KdeLayout
MacLayout
WinLayout
Additionally, button boxes that contain only buttons with
ActionRoleorHelpRolecan be considered modeless and have an alternate look on macOS:
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 anAcceptRole,RejectRole, orHelpRole, theaccepted(),rejected(), orhelpRequested()signals are emitted respectively.If you want a specific button to be default you need to call
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 theautoDefaultproperty, the first push button with the accept role is made the default button when theQDialogButtonBoxis shown,See also
- class PySide2.QtWidgets.QDialogButtonBox(buttons[, parent=None])露
PySide2.QtWidgets.QDialogButtonBox(buttons, orientation[, parent=None])
PySide2.QtWidgets.QDialogButtonBox([parent=None])
PySide2.QtWidgets.QDialogButtonBox(orientation[, parent=None])
- param parent:
- param buttons:
StandardButtons- param orientation:
Constructs a horizontal button box with the given
parent, containing the standard buttons specified bybuttons.See also
Constructs a button box with the given
orientationandparent, containing the standard buttons specified bybuttons.See also
Constructs an empty, horizontal button box with the given
parent.See also
Constructs an empty button box with the given
orientationandparent.See also
- PySide2.QtWidgets.QDialogButtonBox.ButtonRole露
This enum describes the roles that can be used to describe buttons in the button box. Combinations of these roles are as flags used to describe different aspects of their behavior.
Constant
Description
QDialogButtonBox.InvalidRole
The button is invalid.
QDialogButtonBox.AcceptRole
Clicking the button causes the dialog to be accepted (e.g. OK).
QDialogButtonBox.RejectRole
Clicking the button causes the dialog to be rejected (e.g. Cancel).
QDialogButtonBox.DestructiveRole
Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog.
QDialogButtonBox.ActionRole
Clicking the button causes changes to the elements within the dialog.
QDialogButtonBox.HelpRole
The button can be clicked to request help.
QDialogButtonBox.YesRole
The button is a 鈥淵es鈥-like button.
QDialogButtonBox.NoRole
The button is a 鈥淣o鈥-like button.
QDialogButtonBox.ApplyRole
The button applies current changes.
QDialogButtonBox.ResetRole
The button resets the dialog鈥檚 fields to default values.
See also
StandardButton
- PySide2.QtWidgets.QDialogButtonBox.StandardButton露
These enums describe flags for standard buttons. Each button has a defined
ButtonRole.Constant
Description
QDialogButtonBox.Ok
An 鈥淥K鈥 button defined with the
AcceptRole.QDialogButtonBox.Open
An 鈥淥pen鈥 button defined with the
AcceptRole.QDialogButtonBox.Save
A 鈥淪ave鈥 button defined with the
AcceptRole.QDialogButtonBox.Cancel
A 鈥淐ancel鈥 button defined with the
RejectRole.QDialogButtonBox.Close
A 鈥淐lose鈥 button defined with the
RejectRole.QDialogButtonBox.Discard
A 鈥淒iscard鈥 or 鈥淒on鈥檛 Save鈥 button, depending on the platform, defined with the
DestructiveRole.QDialogButtonBox.Apply
An 鈥淎pply鈥 button defined with the
ApplyRole.QDialogButtonBox.Reset
A 鈥淩eset鈥 button defined with the
ResetRole.QDialogButtonBox.RestoreDefaults
A 鈥淩estore Defaults鈥 button defined with the
ResetRole.QDialogButtonBox.Help
A 鈥淗elp鈥 button defined with the
HelpRole.QDialogButtonBox.SaveAll
A 鈥淪ave All鈥 button defined with the
AcceptRole.QDialogButtonBox.Yes
A 鈥淵es鈥 button defined with the
YesRole.QDialogButtonBox.YesToAll
A 鈥淵es to All鈥 button defined with the
YesRole.QDialogButtonBox.No
A 鈥淣o鈥 button defined with the
NoRole.QDialogButtonBox.NoToAll
A 鈥淣o to All鈥 button defined with the
NoRole.QDialogButtonBox.Abort
An 鈥淎bort鈥 button defined with the
RejectRole.QDialogButtonBox.Retry
A 鈥淩etry鈥 button defined with the
AcceptRole.QDialogButtonBox.Ignore
An 鈥淚gnore鈥 button defined with the
AcceptRole.QDialogButtonBox.NoButton
An invalid button.
See also
ButtonRolestandardButtons
- PySide2.QtWidgets.QDialogButtonBox.ButtonLayout露
This enum describes the layout policy to be used when arranging the buttons contained in the button box.
Constant
Description
QDialogButtonBox.WinLayout
Use a policy appropriate for applications on Windows.
QDialogButtonBox.MacLayout
Use a policy appropriate for applications on macOS.
QDialogButtonBox.KdeLayout
Use a policy appropriate for applications on KDE.
QDialogButtonBox.GnomeLayout
Use a policy appropriate for applications on GNOME.
QDialogButtonBox.AndroidLayout
Use a policy appropriate for applications on Android. This enum value was added in Qt 5.10.
The button layout is specified by the
current style. However, on the X11 platform, it may be influenced by the desktop environment.
- PySide2.QtWidgets.QDialogButtonBox.accepted()露
- PySide2.QtWidgets.QDialogButtonBox.addButton(button, role)露
- Parameters:
button 鈥
PySide2.QtWidgets.QAbstractButtonrole 鈥
ButtonRole
Adds the given
buttonto the button box with the specifiedrole. If the role is invalid, the button is not added.If the button has already been added, it is removed and added again with the new role.
Note
The button box takes ownership of the button.
See also
- PySide2.QtWidgets.QDialogButtonBox.addButton(button)
- Parameters:
button 鈥
StandardButton- Return type:
Adds a standard
buttonto the button box if it is valid to do so, and returns a push button. Ifbuttonis invalid, it is not added to the button box, and zero is returned.See also
- PySide2.QtWidgets.QDialogButtonBox.addButton(text, role)
- Parameters:
text 鈥 str
role 鈥
ButtonRole
- Return type:
- PySide2.QtWidgets.QDialogButtonBox.button(which)露
- Parameters:
which 鈥
StandardButton- Return type:
Returns the
QPushButtoncorresponding to the standard buttonwhich, orNoneif the standard button doesn鈥檛 exist in this button box.See also
- PySide2.QtWidgets.QDialogButtonBox.buttonRole(button)露
- Parameters:
button 鈥
PySide2.QtWidgets.QAbstractButton- Return type:
Returns the button role for the specified
button. This function returnsInvalidRoleifbuttonisNoneor has not been added to the button box.See also
- PySide2.QtWidgets.QDialogButtonBox.buttons()露
- Return type:
Returns a list of all the buttons that have been added to the button box.
See also
- PySide2.QtWidgets.QDialogButtonBox.centerButtons()露
- Return type:
bool
This property holds whether the buttons in the button box are centered.
By default, this property is
false. This behavior is appropriate for most types of dialogs. A notable exception is message boxes on most platforms (e.g. Windows), where the button box is centered horizontally.See also
- PySide2.QtWidgets.QDialogButtonBox.clear()露
Clears the button box, deleting all buttons within it.
See also
- PySide2.QtWidgets.QDialogButtonBox.clicked(button)露
- Parameters:
button 鈥
PySide2.QtWidgets.QAbstractButton
- PySide2.QtWidgets.QDialogButtonBox.helpRequested()露
- PySide2.QtWidgets.QDialogButtonBox.orientation()露
- Return type:
This property holds the orientation of the button box.
By default, the orientation is horizontal (i.e. the buttons are laid out side by side). The possible orientations are
HorizontalandVertical.
- PySide2.QtWidgets.QDialogButtonBox.rejected()露
- PySide2.QtWidgets.QDialogButtonBox.removeButton(button)露
- Parameters:
button 鈥
PySide2.QtWidgets.QAbstractButton
Removes
buttonfrom the button box without deleting it and sets its parent to zero.See also
- PySide2.QtWidgets.QDialogButtonBox.setCenterButtons(center)露
- Parameters:
center 鈥 bool
This property holds whether the buttons in the button box are centered.
By default, this property is
false. This behavior is appropriate for most types of dialogs. A notable exception is message boxes on most platforms (e.g. Windows), where the button box is centered horizontally.See also
- PySide2.QtWidgets.QDialogButtonBox.setOrientation(orientation)露
- Parameters:
orientation 鈥
Orientation
This property holds the orientation of the button box.
By default, the orientation is horizontal (i.e. the buttons are laid out side by side). The possible orientations are
HorizontalandVertical.
- PySide2.QtWidgets.QDialogButtonBox.setStandardButtons(buttons)露
- Parameters:
buttons 鈥
StandardButtons
This property holds collection of standard buttons in the button box.
This property controls which standard buttons are used by the button box.
See also
- PySide2.QtWidgets.QDialogButtonBox.standardButton(button)露
- Parameters:
button 鈥
PySide2.QtWidgets.QAbstractButton- Return type:
Returns the standard button enum value corresponding to the given
button, orNoButtonif the givenbuttonisn鈥檛 a standard button.See also
- PySide2.QtWidgets.QDialogButtonBox.standardButtons()露
- Return type:
StandardButtons
This property holds collection of standard buttons in the button box.
This property controls which standard buttons are used by the button box.
See also
漏 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.









