|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QDialogButtonBox
public class QDialogButtonBox
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:
![]() | 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 WinLayout |
The buttons are laid out the following way if the button box is vertical:
![]() | Button box laid out in vertical GnomeLayout |
![]() | Button box laid out in vertical KdeLayout |
![]() | Button box laid out in vertical MacLayout |
![]() | Button 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:
![]() | 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 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,
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.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 |
---|
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.
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.
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.
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.
Constructor Detail |
---|
public QDialogButtonBox(QDialogButtonBox.StandardButtons buttons, Qt.Orientation orientation)
Equivalent to QDialogButtonBox(buttons, orientation, 0).
public QDialogButtonBox(QDialogButtonBox.StandardButtons buttons)
Equivalent to QDialogButtonBox(buttons, Qt::Horizontal, 0).
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.
public QDialogButtonBox()
Equivalent to QDialogButtonBox(0).
public QDialogButtonBox(QWidget parent)
Constructs an empty, horizontal button box with the given parent.
public QDialogButtonBox(Qt.Orientation orientation)
Equivalent to QDialogButtonBox(orientation, 0).
public QDialogButtonBox(Qt.Orientation orientation, QWidget parent)
Constructs an empty button box with the given orientation and parent.
Method Detail |
---|
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.
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.
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.
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.
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.
public final java.util.List<QAbstractButton> buttons()
Returns a list of all the buttons that have been added to the button box.
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.
public final void clear()
Clears the button box, deleting all buttons within it.
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.
public final void removeButton(QAbstractButton button)
Removes button from the button box without deleting it and sets its parent to zero.
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.
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.
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.
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.
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.
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.
protected void changeEvent(QEvent event)
This function is reimplemented for internal reasons.
changeEvent
in class QWidget
public boolean event(QEvent event)
This function is reimplemented for internal reasons.
event
in class QWidget
public static QDialogButtonBox fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |