Table Of Contents

Previous topic

QDockWidget

Next topic

QDial

QDialogButtonBox

Inheritance diagram of QDialogButtonBox

Synopsis

Functions

Signals

Detailed Description

The PySide.QtGui.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. PySide.QtGui.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 PySide.QtGui.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, PySide.QtGui.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.

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:

../../_images/buttonbox-gnomelayout-horizontal.png Button box laid out in horizontal GnomeLayout
../../_images/buttonbox-kdelayout-horizontal.png Button box laid out in horizontal KdeLayout
../../_images/buttonbox-maclayout-horizontal.png Button box laid out in horizontal MacLayout
../../_images/buttonbox-winlayout-horizontal.png Button box laid out in horizontal WinLayout

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

GnomeLayout KdeLayout MacLayout WinLayout
../../_images/buttonbox-gnomelayout-vertical.png ../../_images/buttonbox-kdelayout-vertical.png ../../_images/buttonbox-maclayout-vertical.png ../../_images/buttonbox-winlayout-vertical.png

Additionally, button boxes that contain only buttons with ActionRole or HelpRole can be considered modeless and have an alternate look on Mac OS X:

modeless horizontal MacLayout ../../_images/buttonbox-mac-modeless-horizontal.png

When a button is clicked in the button box, the PySide.QtGui.QDialogButtonBox.clicked() signal is emitted for the actual button is that is pressed. For convenience, if the button has an AcceptRole , RejectRole , or HelpRole , the PySide.QtGui.QDialogButtonBox.accepted() , PySide.QtGui.QDialogButtonBox.rejected() , or PySide.QtGui.QDialogButtonBox.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 PySide.QtGui.QDialogButtonBox is shown,

class PySide.QtGui.QDialogButtonBox(buttons[, orientation=Qt.Horizontal[, parent=None]])
class PySide.QtGui.QDialogButtonBox([parent=None])
class PySide.QtGui.QDialogButtonBox(orientation[, parent=None])
Parameters:
  • parentPySide.QtGui.QWidget
  • buttonsPySide.QtGui.QDialogButtonBox.StandardButtons
  • orientationPySide.QtCore.Qt.Orientation

Constructs an empty, horizontal button box with the given parent .

PySide.QtGui.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 Mac OS X.
QDialogButtonBox.KdeLayout Use a policy appropriate for applications on KDE.
QDialogButtonBox.GnomeLayout Use a policy appropriate for applications on GNOME.

The button layout is specified by the current style . However, on the X11 platform, it may be influenced by the desktop environment.

PySide.QtGui.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 “Yes”-like button.
QDialogButtonBox.NoRole The button is a “No”-like button.
QDialogButtonBox.ApplyRole The button applies current changes.
QDialogButtonBox.ResetRole The button resets the dialog’s fields to default values.

See also

QDialogButtonBox.StandardButton

PySide.QtGui.QDialogButtonBox.StandardButton

These enums describe flags for standard buttons. Each button has a defined QDialogButtonBox.ButtonRole .

Constant Description
QDialogButtonBox.Ok An “OK” button defined with the AcceptRole .
QDialogButtonBox.Open A “Open” button defined with the AcceptRole .
QDialogButtonBox.Save A “Save” button defined with the AcceptRole .
QDialogButtonBox.Cancel A “Cancel” button defined with the RejectRole .
QDialogButtonBox.Close A “Close” button defined with the RejectRole .
QDialogButtonBox.Discard A “Discard” or “Don’t Save” button, depending on the platform, defined with the DestructiveRole .
QDialogButtonBox.Apply An “Apply” button defined with the ApplyRole .
QDialogButtonBox.Reset A “Reset” button defined with the ResetRole .
QDialogButtonBox.RestoreDefaults A “Restore Defaults” button defined with the ResetRole .
QDialogButtonBox.Help A “Help” button defined with the HelpRole .
QDialogButtonBox.SaveAll A “Save All” button defined with the AcceptRole .
QDialogButtonBox.Yes A “Yes” button defined with the YesRole .
QDialogButtonBox.YesToAll A “Yes to All” button defined with the YesRole .
QDialogButtonBox.No A “No” button defined with the NoRole .
QDialogButtonBox.NoToAll A “No to All” button defined with the NoRole .
QDialogButtonBox.Abort An “Abort” button defined with the RejectRole .
QDialogButtonBox.Retry A “Retry” button defined with the AcceptRole .
QDialogButtonBox.Ignore An “Ignore” button defined with the AcceptRole .
QDialogButtonBox.NoButton An invalid button.

See also

QDialogButtonBox.ButtonRole PySide.QtGui.QDialogButtonBox.standardButtons()

PySide.QtGui.QDialogButtonBox.accepted()
PySide.QtGui.QDialogButtonBox.addButton(text, role)
Parameters:
Return type:

PySide.QtGui.QPushButton

Creates a push button with the given text , adds it to the button box for the specified role , and returns the corresponding push button. If role is invalid, no button is created, and zero is returned.

PySide.QtGui.QDialogButtonBox.addButton(button)
Parameters:buttonPySide.QtGui.QDialogButtonBox.StandardButton
Return type:PySide.QtGui.QPushButton

Adds a standard button to the button box if it is valid to do so, and returns a push button. If button is invalid, it is not added to the button box, and zero is returned.

PySide.QtGui.QDialogButtonBox.addButton(button, role)
Parameters:

Adds the given button to the button box with the specified role . 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.

PySide.QtGui.QDialogButtonBox.button(which)
Parameters:whichPySide.QtGui.QDialogButtonBox.StandardButton
Return type:PySide.QtGui.QPushButton

Returns the PySide.QtGui.QPushButton corresponding to the standard button which , or 0 if the standard button doesn’t exist in this button box.

PySide.QtGui.QDialogButtonBox.buttonRole(button)
Parameters:buttonPySide.QtGui.QAbstractButton
Return type:PySide.QtGui.QDialogButtonBox.ButtonRole

Returns the button role for the specified button . This function returns InvalidRole if button is 0 or has not been added to the button box.

PySide.QtGui.QDialogButtonBox.buttons()
Return type:

Returns a list of all the buttons that have been added to the button box.

PySide.QtGui.QDialogButtonBox.centerButtons()
Return type:PySide.QtCore.bool

This property holds whether the buttons in the button box are centered.

By default, this property is false. This behavior is appopriate for most types of dialogs. A notable exception is message boxes on most platforms (e.g. Windows), where the button box is centered horizontally.

PySide.QtGui.QDialogButtonBox.clear()

Clears the button box, deleting all buttons within it.

PySide.QtGui.QDialogButtonBox.clicked(button)
Parameters:buttonPySide.QtGui.QAbstractButton
PySide.QtGui.QDialogButtonBox.helpRequested()
PySide.QtGui.QDialogButtonBox.orientation()
Return type:PySide.QtCore.Qt.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 Qt.Horizontal and Qt.Vertical .

PySide.QtGui.QDialogButtonBox.rejected()
PySide.QtGui.QDialogButtonBox.removeButton(button)
Parameters:buttonPySide.QtGui.QAbstractButton

Removes button from the button box without deleting it and sets its parent to zero.

PySide.QtGui.QDialogButtonBox.setCenterButtons(center)
Parameters:centerPySide.QtCore.bool

This property holds whether the buttons in the button box are centered.

By default, this property is false. This behavior is appopriate for most types of dialogs. A notable exception is message boxes on most platforms (e.g. Windows), where the button box is centered horizontally.

PySide.QtGui.QDialogButtonBox.setOrientation(orientation)
Parameters:orientationPySide.QtCore.Qt.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 Qt.Horizontal and Qt.Vertical .

PySide.QtGui.QDialogButtonBox.setStandardButtons(buttons)
Parameters:buttonsPySide.QtGui.QDialogButtonBox.StandardButtons

This property holds collection of standard buttons in the button box.

This property controls which standard buttons are used by the button box.

PySide.QtGui.QDialogButtonBox.standardButton(button)
Parameters:buttonPySide.QtGui.QAbstractButton
Return type:PySide.QtGui.QDialogButtonBox.StandardButton

Returns the standard button enum value corresponding to the given button , or NoButton if the given button isn’t a standard button.

PySide.QtGui.QDialogButtonBox.standardButtons()
Return type:PySide.QtGui.QDialogButtonBox.StandardButtons

This property holds collection of standard buttons in the button box.

This property controls which standard buttons are used by the button box.