CopperSpice API  1.9.1
QDialogButtonBox Class Reference

A widget which displays buttons in a layout appropriate to the current widget style. More...

Inheritance diagram for QDialogButtonBox:
QWidget QObject QPaintDevice

Public Typedefs

using StandardButtons = QFlags< StandardButton >
 
- Public Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 

Public Types

enum  ButtonLayout
 
enum  ButtonRole
 
enum  StandardButton
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Public Signals

void accepted ()
 
void clicked (QAbstractButton *button)
 
void helpRequested ()
 
void rejected ()
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Methods

 QDialogButtonBox (Qt::Orientation orientation, QWidget *parent=nullptr)
 
 QDialogButtonBox (QWidget *parent=nullptr)
 
 QDialogButtonBox (StandardButtons buttons, Qt::Orientation orientation, QWidget *parent=nullptr)
 
 QDialogButtonBox (StandardButtons buttons, QWidget *parent=nullptr)
 
 ~QDialogButtonBox ()
 
QPushButtonaddButton (const QString &text, ButtonRole role)
 
void addButton (QAbstractButton *button, ButtonRole role)
 
QPushButtonaddButton (StandardButton button)
 
QPushButtonbutton (StandardButton which) const
 
ButtonRole buttonRole (QAbstractButton *button) const
 
QList< QAbstractButton * > buttons () const
 
bool centerButtons () const
 
void clear ()
 
Qt::Orientation orientation () const
 
void removeButton (QAbstractButton *button)
 
void setCenterButtons (bool center)
 
void setOrientation (Qt::Orientation orientation)
 
void setStandardButtons (StandardButtons buttons)
 
StandardButton standardButton (QAbstractButton *button) const
 
StandardButtons standardButtons () const
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
virtual bool hasHeightForWidth () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int width) const
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
virtual QSize minimumSizeHint () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
virtual QSize sizeHint () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

void changeEvent (QEvent *event) override
 
bool event (QEvent *event) override
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
virtual void contextMenuEvent (QContextMenuEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void dragEnterEvent (QDragEnterEvent *event)
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event)
 
virtual void dropEvent (QDropEvent *event)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
virtual void focusInEvent (QFocusEvent *event)
 
bool focusNextChild ()
 
virtual bool focusNextPrevChild (bool next)
 
virtual void focusOutEvent (QFocusEvent *event)
 
bool focusPreviousChild ()
 
virtual void hideEvent (QHideEvent *event)
 
void initPainter (QPainter *painter) const override
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void mouseMoveEvent (QMouseEvent *event)
 
virtual void mousePressEvent (QMouseEvent *event)
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void paintEvent (QPaintEvent *event)
 
virtual void resizeEvent (QResizeEvent *event)
 
virtual void showEvent (QShowEvent *event)
 
virtual void tabletEvent (QTabletEvent *event)
 
virtual void wheelEvent (QWheelEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 centerButtons
 
 orientation
 
 standardButtons
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Detailed Description

The QDialogButtonBox class is a widget which displayss buttons in a layout 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:

GnomeLayout Horizontal Button box laid out in horizontal GnomeLayout
KdeLayout Horizontal Button box laid out in horizontal KdeLayout
MacLayout Horizontal Button box laid out in horizontal MacLayout
WinLayout Horizontal Button box laid out in horizontal WinLayout

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

GnomeLayoutKdeLayoutMacLayoutWinLayout
GnomeLayout VerticalKdeLayout VerticalMacLayout VerticalWinLayout Vertical

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 Screenshot of modeless horizontal 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
QDialog, QMessageBox, QPushButton,

Member Typedef Documentation

Member Enumeration Documentation

This enum describes the layout policy to be used when arranging the buttons contained in the button box. The button layout is specified by the current style. However, on the X11 platform, it may be influenced by the desktop environment.

ConstantValueDescription
QDialogButtonBox::WinLayout0Use a policy appropriate for applications on Windows.
QDialogButtonBox::MacLayout1Use a policy appropriate for applications on Mac OS X.
QDialogButtonBox::KdeLayout2Use a policy appropriate for applications on KDE.
QDialogButtonBox::GnomeLayout3Use a policy appropriate for applications on GNOME.

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.

ConstantValueDescription
QDialogButtonBox::InvalidRole-1The button is invalid.
QDialogButtonBox::AcceptRole0 Clicking the button causes the dialog to be accepted (e.g. OK).
QDialogButtonBox::RejectRole1 Clicking the button causes the dialog to be rejected (e.g. Cancel).
QDialogButtonBox::DestructiveRole2 Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog.
QDialogButtonBox::ActionRole3 Clicking the button causes changes to the elements within the dialog.
QDialogButtonBox::HelpRole4The button can be clicked to request help.
QDialogButtonBox::YesRole5The button is a "Yes"-like button.
QDialogButtonBox::NoRole6The button is a "No"-like button.
QDialogButtonBox::ApplyRole8The button applies current changes.
QDialogButtonBox::ResetRole7The button resets the dialog's fields to default values.
See also
StandardButton

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

ConstantValueDescription
QDialogButtonBox::Ok0x00000400 "OK" button defined with the AcceptRole.
QDialogButtonBox::Open0x00002000 "Open" button defined with the AcceptRole.
QDialogButtonBox::Save0x00000800 "Save" button defined with the AcceptRole.
QDialogButtonBox::Cancel0x00400000 "Cancel" button defined with the RejectRole.
QDialogButtonBox::Close0x00200000 "Close" button defined with the RejectRole.
QDialogButtonBox::Discard0x00800000 "Discard" or "Do not Save" button, depending on the platform, defined with the DestructiveRole.
QDialogButtonBox::Apply0x02000000 "Apply" button defined with the ApplyRole.
QDialogButtonBox::Reset0x04000000 "Reset" button defined with the ResetRole.
QDialogButtonBox::RestoreDefaults0x08000000 "Restore Defaults" button defined with the ResetRole.
QDialogButtonBox::Help0x01000000 "Help" button defined with the HelpRole.
QDialogButtonBox::SaveAll0x00001000 "Save All" button defined with the AcceptRole.
QDialogButtonBox::Yes0x00004000 "Yes" button defined with the YesRole.
QDialogButtonBox::YesToAll0x00008000 "Yes to All" button defined with the YesRole.
QDialogButtonBox::No0x00010000 "No" button defined with the NoRole.
QDialogButtonBox::NoToAll0x00020000 "No to All" button defined with the NoRole.
QDialogButtonBox::Abort0x00040000 "Abort" button defined with the RejectRole.
QDialogButtonBox::Retry0x00080000 "Retry" button defined with the AcceptRole.
QDialogButtonBox::Ignore0x00100000 "Ignore" button defined with the AcceptRole.
QDialogButtonBox::NoButton0x00000000 An invalid button.
See also
ButtonRole, standardButtons

Constructor & Destructor Documentation

QDialogButtonBox::QDialogButtonBox ( QWidget parent = nullptr)

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

See also
orientation, addButton()
QDialogButtonBox::QDialogButtonBox ( Qt::Orientation  orientation,
QWidget parent = nullptr 
)

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

See also
orientation, addButton()
QDialogButtonBox::QDialogButtonBox ( StandardButtons  buttons,
Qt::Orientation  orientation = Qt::Horizontal,
QWidget parent = nullptr 
)

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

See also
orientation, addButton()
QDialogButtonBox::QDialogButtonBox ( StandardButtons  buttons,
QWidget parent = nullptr 
)
explicit

Constructs a button box with the given parent, containing the standard buttons specified by buttons.

QDialogButtonBox::~QDialogButtonBox ( )

Destroys the button box.

Method Documentation

void QDialogButtonBox::accepted ( )
signal

This signal is emitted when a button inside the button box is clicked, as long as it was defined with the AcceptRole or YesRole.

See also
rejected(), clicked(), helpRequested()
QPushButton * QDialogButtonBox::addButton ( const QString text,
ButtonRole  role 
)

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.

See also
removeButton(), clear()
void QDialogButtonBox::addButton ( QAbstractButton button,
ButtonRole  role 
)

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.
See also
removeButton(), clear()
QPushButton * QDialogButtonBox::addButton ( StandardButton  button)

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.

See also
removeButton(), clear()
QPushButton * QDialogButtonBox::button ( StandardButton  which) const

Returns the QPushButton corresponding to the standard button which or a nullptr if the standard button does not exist in this button box.

See also
standardButton(), standardButtons(), buttons()
ButtonRole QDialogButtonBox::buttonRole ( QAbstractButton button) const

Returns the button role for the specified button. This method returns InvalidRole if button is a nullptr or has not been added to the button box.

See also
buttons(), addButton()
QList< QAbstractButton * > QDialogButtonBox::buttons ( ) const

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

See also
buttonRole(), addButton(), removeButton()
bool QDialogButtonBox::centerButtons ( ) const

Returns the value of the property.

void QDialogButtonBox::changeEvent ( QEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::changeEvent()

void QDialogButtonBox::clear ( )

Clears the button box, deleting all buttons within it.

See also
removeButton(), addButton()
void QDialogButtonBox::clicked ( QAbstractButton button)
signal

This signal is emitted when a button inside the button box is clicked. The specific button that was pressed is specified by button.

See also
accepted(), rejected(), helpRequested()
bool QDialogButtonBox::event ( QEvent event)
overrideprotected

Reimplemented from QWidget::event()

void QDialogButtonBox::helpRequested ( )
signal

This signal is emitted when a button inside the button box is clicked, as long as it was defined with the HelpRole.

See also
accepted(), rejected(), clicked()
Qt::Orientation QDialogButtonBox::orientation ( ) const

Returns the value of the property.

void QDialogButtonBox::rejected ( )
signal

This signal is emitted when a button inside the button box is clicked, as long as it was defined with the RejectRole or NoRole.

See also
accepted(), helpRequested(), clicked()
void QDialogButtonBox::removeButton ( QAbstractButton button)

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

See also
clear(), buttons(), addButton()
void QDialogButtonBox::setCenterButtons ( bool  center)

Sets the value of the property to center.

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

Sets the value of the property to orientation.

void QDialogButtonBox::setStandardButtons ( StandardButtons  buttons)

Sets the value of the property to buttons.

StandardButton QDialogButtonBox::standardButton ( QAbstractButton button) const

Returns the standard button enum value corresponding to the given button, or NoButton if the given button is not a standard button.

See also
button(), buttons(), standardButtons()
StandardButtons QDialogButtonBox::standardButtons ( ) const

Returns the value of the property.

Property Documentation

QDialogButtonBox::centerButtons

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
QMessageBox
PropertiesClass Methods
read centerButtons
write setCenterButtons
QDialogButtonBox::orientation

This property holds the orientation of the button box. By default the orientation is horizontal and the buttons are laid out side by side. The possible orientations are Qt::Horizontal and Qt::Vertical.

PropertiesClass Methods
read orientation
write setOrientation
QDialogButtonBox::standardButtons

This property holds a collection of standard buttons in the button box amd controls which standard buttons are used by the button box.

See also
addButton()
PropertiesClass Methods
read standardButtons
write setStandardButtons