Qt Jambi Home

com.trolltech.qt.gui
Class QDialogButtonBox

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.gui.QDialogButtonBox
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QDialogButtonBox
extends QWidget

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:

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 HorizontalButton box laid out in horizontal GnomeLayout
KdeLayout HorizontalButton box laid out in horizontal KdeLayout
MacLayout HorizontalButton box laid out in horizontal MacLayout
WinLayout HorizontalButton box laid out in horizontal WinLayout

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

GnomeLayout VerticalButton box laid out in vertical GnomeLayout
KdeLayout VerticalButton box laid out in vertical KdeLayout
MacLayout VerticalButton box laid out in vertical MacLayout
WinLayout VerticalButton 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:

Screenshot of modeless horizontal MacLayoutmodeless horizontal MacLayout
Screenshot of modeless vertical MacLayoutmodeless 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, QDialog

Nested Class Summary
static class QDialogButtonBox.ButtonLayout
          This enum describes the layout policy to be used when arranging the buttons contained in the button box.
static class QDialogButtonBox.ButtonRole
          This enum describes the roles that can be used to describe buttons in the button box.
static class QDialogButtonBox.StandardButton
          These enums describe flags for standard buttons.
static class QDialogButtonBox.StandardButtons
          This QFlag class provides flags for the int enum.
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
QWidget.RenderFlag, QWidget.RenderFlags
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 QSignalEmitter.Signal0 accepted
          This signal is emitted when a button inside the button box is clicked, as long as it was defined with the AcceptRole or YesRole.
 QSignalEmitter.Signal1<QAbstractButton> clicked
          This signal is emitted when a button inside the button box is clicked.
 QSignalEmitter.Signal0 helpRequested
          This signal is emitted when a button inside the button box is clicked, as long as it was defined with the HelpRole.
 QSignalEmitter.Signal0 rejected
          This signal is emitted when a button inside the button box is clicked, as long as it was defined with the RejectRole or NoRole.
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Constructor Summary
QDialogButtonBox()
          Equivalent to QDialogButtonBox(0).
QDialogButtonBox(QDialogButtonBox.StandardButtons buttons)
          Equivalent to QDialogButtonBox(buttons, Qt::Horizontal, 0).
QDialogButtonBox(QDialogButtonBox.StandardButtons buttons, Qt.Orientation orientation)
          Equivalent to QDialogButtonBox(buttons, orientation, 0).
QDialogButtonBox(QDialogButtonBox.StandardButtons buttons, Qt.Orientation orientation, QWidget parent)
          Constructs a button box with the given orientation and parent, containing the standard buttons specified by buttons.
QDialogButtonBox(Qt.Orientation orientation)
          Equivalent to QDialogButtonBox(orientation, 0).
QDialogButtonBox(Qt.Orientation orientation, QWidget parent)
          Constructs an empty button box with the given orientation and parent.
QDialogButtonBox(QWidget parent)
          Constructs an empty, horizontal button box with the given parent.
 
Method Summary
 void addButton(QAbstractButton button, QDialogButtonBox.ButtonRole role)
          Adds the given button to the button box with the specified role.
 QPushButton addButton(QDialogButtonBox.StandardButton button)
          Adds a standard button to the button box if it is valid to do so, and returns a push button.
 QPushButton addButton(java.lang.String text, QDialogButtonBox.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.
 QPushButton button(QDialogButtonBox.StandardButton which)
          Returns the QPushButton corresponding to the standard button which, or 0 if the standard button doesn't exist in this button box.
 QDialogButtonBox.ButtonRole buttonRole(QAbstractButton button)
          Returns the button role for the specified button.
 java.util.List<QAbstractButton> buttons()
          Returns a list of all the buttons that have been added to the button box.
 boolean centerButtons()
          Returns whether the buttons in the button box are centered.
protected  void changeEvent(QEvent event)
          This function is reimplemented for internal reasons.
 void clear()
          Clears the button box, deleting all buttons within it.
 boolean event(QEvent event)
          This function is reimplemented for internal reasons.
static QDialogButtonBox fromNativePointer(QNativePointer nativePointer)
          This function returns the QDialogButtonBox instance pointed to by nativePointer
 Qt.Orientation orientation()
          Returns the orientation of the button box.
 void removeButton(QAbstractButton button)
          Removes button from the button box without deleting it and sets its parent to zero.
 void setCenterButtons(boolean center)
          Sets whether the buttons in the button box are centered to center.
 void setOrientation(Qt.Orientation orientation)
          Sets the orientation of the button box to orientation.
 void setStandardButtons(QDialogButtonBox.StandardButton... buttons)
          Sets collection of standard buttons in the button box to buttons.
 void setStandardButtons(QDialogButtonBox.StandardButtons buttons)
          Sets collection of standard buttons in the button box to buttons.
 QDialogButtonBox.StandardButton standardButton(QAbstractButton button)
          Returns the standard button enum value corresponding to the given button, or NoButton if the given button isn't a standard button.
 QDialogButtonBox.StandardButtons standardButtons()
          Returns collection of standard buttons in the button box.
 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuEvent, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, ensurePolished, enterEvent, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyPressEvent, keyReleaseEvent, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumSizeHint, minimumWidth, mouseDoubleClickEvent, mouseGrabber, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintEngine, paintEvent, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, resizeEvent, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeHint, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

accepted

public final QSignalEmitter.Signal0 accepted

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

Compatible Slot Signature:
void mySlot()
See Also:
rejected, clicked, helpRequested


clicked

public final QSignalEmitter.Signal1<QAbstractButton> clicked

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

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QAbstractButton button)
void mySlot()
See Also:
accepted, rejected, helpRequested


helpRequested

public final QSignalEmitter.Signal0 helpRequested

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

Compatible Slot Signature:
void mySlot()
See Also:
accepted, rejected, clicked


rejected

public final QSignalEmitter.Signal0 rejected

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

Compatible Slot Signature:
void mySlot()
See Also:
accepted, helpRequested, clicked

Constructor Detail

QDialogButtonBox

public QDialogButtonBox(QDialogButtonBox.StandardButtons buttons,
                        Qt.Orientation orientation)

Equivalent to QDialogButtonBox(buttons, orientation, 0).


QDialogButtonBox

public QDialogButtonBox(QDialogButtonBox.StandardButtons buttons)

Equivalent to QDialogButtonBox(buttons, Qt::Horizontal, 0).


QDialogButtonBox

public QDialogButtonBox(QDialogButtonBox.StandardButtons buttons,
                        Qt.Orientation orientation,
                        QWidget parent)

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

See Also:
orientation, addButton

QDialogButtonBox

public QDialogButtonBox()

Equivalent to QDialogButtonBox(0).


QDialogButtonBox

public QDialogButtonBox(QWidget parent)

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

See Also:
orientation, addButton

QDialogButtonBox

public QDialogButtonBox(Qt.Orientation orientation)

Equivalent to QDialogButtonBox(orientation, 0).


QDialogButtonBox

public QDialogButtonBox(Qt.Orientation orientation,
                        QWidget parent)

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

See Also:
orientation, addButton
Method Detail

addButton

public final void addButton(QAbstractButton button,
                            QDialogButtonBox.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.

See Also:
removeButton, clear

addButton

public final QPushButton addButton(java.lang.String text,
                                   QDialogButtonBox.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

addButton

public final QPushButton addButton(QDialogButtonBox.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

button

public final QPushButton button(QDialogButtonBox.StandardButton which)

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

See Also:
standardButton, standardButtons, buttons

buttonRole

public final QDialogButtonBox.ButtonRole buttonRole(QAbstractButton button)

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.

See Also:
buttons, addButton

buttons

public final java.util.List<QAbstractButton> buttons()

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

See Also:
buttonRole, addButton, removeButton

centerButtons

public final boolean centerButtons()

Returns 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.

See Also:
setCenterButtons, QMessageBox

clear

public final void clear()

Clears the button box, deleting all buttons within it.

See Also:
removeButton, addButton

orientation

public final Qt.Orientation orientation()

Returns 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.

See Also:
setOrientation

removeButton

public final void removeButton(QAbstractButton button)

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

See Also:
clear, buttons, addButton

setCenterButtons

public final void setCenterButtons(boolean center)

Sets whether the buttons in the button box are centered to center.

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.

See Also:
centerButtons, QMessageBox

setOrientation

public final void setOrientation(Qt.Orientation orientation)

Sets the orientation of the button box to orientation.

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.

See Also:
orientation

setStandardButtons

public final void setStandardButtons(QDialogButtonBox.StandardButton... buttons)

Sets collection of standard buttons in the button box to buttons.

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

See Also:
standardButtons, addButton

setStandardButtons

public final void setStandardButtons(QDialogButtonBox.StandardButtons buttons)

Sets collection of standard buttons in the button box to buttons.

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

See Also:
standardButtons, addButton

standardButton

public final QDialogButtonBox.StandardButton standardButton(QAbstractButton button)

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

See Also:
button, buttons, standardButtons

standardButtons

public final QDialogButtonBox.StandardButtons standardButtons()

Returns collection of standard buttons in the button box.

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

See Also:
setStandardButtons, addButton

changeEvent

protected void changeEvent(QEvent event)

This function is reimplemented for internal reasons.

Overrides:
changeEvent in class QWidget

event

public boolean event(QEvent event)

This function is reimplemented for internal reasons.

Overrides:
event in class QWidget
See Also:
closeEvent, focusInEvent, focusOutEvent, enterEvent, keyPressEvent, keyReleaseEvent, leaveEvent, mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, moveEvent, paintEvent, resizeEvent, QObject::event, QObject::timerEvent

fromNativePointer

public static QDialogButtonBox fromNativePointer(QNativePointer nativePointer)
This function returns the QDialogButtonBox instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home