com.trolltech.qt.gui
Class QMessageBox

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      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.QDialog
                          extended by com.trolltech.qt.gui.QMessageBox
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QMessageBox
extends QDialog

The QMessageBox class provides a modal dialog for informing the user or for asking the user a question and receiving an answer. A message box displays a primary text to alert the user to a situation, an informative text to further explain the alert or to ask the user a question, and an optional detailed text to provide even more data if the user requests it. A message box can also display an icon and standard buttons for accepting a user response.

Two APIs for using QMessageBox are provided, the property-based API, and the static functions. Calling one of the static functions is the simpler approach, but it is less flexible than using the property-based API, and the result is less informative. Using the property-based API is recommended.

The Property-based API

To use the property-based API, construct an instance of QMessageBox, set the desired properties, and call exec() to show the message. The simplest configuration is to set only the message text property.Error parsing snippet. The user must click the OK button to dismiss the message box. The rest of the GUI is blocked until the message box is dismissed.

A better approach than just alerting the user to an event is to also ask the user what to do about it. Store the question in the informative text property, and set the standard buttons property to the set of buttons you want as the set of user responses. The buttons are specified by combining values from StandardButtons using the bitwise OR operator. The display order for the buttons is platform-dependent. For example, on Windows, Save is displayed to the left of Cancel, whereas on Mac OS, the order is reversed.

Mark one of your standard buttons to be your default button.Error parsing snippet. This is the approach recommended in the Mac OS X Guidlines. Similar guidlines apply for the other platforms, but note the different ways the informative text is handled for different platforms.


The exec() slot returns the StandardButtons value of the button that was clicked.Error parsing snippet. To give the user more information to help him answer the question, set the detailed text property. If the detailed text property is set, the Show Details... button will be shown.

Clicking the Show Details... button displays the detailed text.

Rich Text and the Text Format Property

The
detailed text property is always interpreted as plain text. The main text and informative text properties can be either plain text or rich text. These strings are interpreted according to the setting of the text format property. The default setting is auto-text .

Note that for some plain text strings containing XML meta-characters, the auto-text rich text detection test may fail causing your plain text string to be interpreted incorrectly as rich text. In these rare cases, use Qt::convertFromPlainText() to convert your plain text string to a visually equivalent rich text string, or set the text format property explicitly with setTextFormat().

Severity Levels and the Icon and Pixmap Properties

QMessageBox supports four predefined message severity levels, or message types, which really only differ in the predefined icon they each show. Specify one of the four predefined message types by setting the icon property to one of the predefined Icons . The following rules are guidelines:


Question For asking a question during normal operations.


Information For reporting information about normal operations.


Warning For reporting non-critical errors.


Critical For reporting critical errors.
The default value is No Icon . The message boxes are otherwise the same for all cases. When using a standard icon, use the one recommended in the table, or use the one recommended by the style guidelines for your platform. If none of the standard icons is right for your message box, you can use a custom icon by setting the icon pixmap property instead of setting the icon property.

In summary, to set an icon, use eithersetIcon() for one of the standard icons, orsetIconPixmap() for a custom icon.

The Static Functions API

Building message boxes with the static functions API, although convenient, is less flexible than using the property-based API, because the static function signatures lack parameters for setting the informative text and detailed text properties. One work-around for this has been to use the title parameter as the message box main text and the text parameter as the message box informative text. Because this has the obvious drawback of making a less readable message box, platform guidelines do not recommend it. The Microsoft Windows User Interface Guidelines recommend using the application name as the window's title, which means that if you have an informative text in addition to your main text, you must concatenate it to the text parameter.

Note that the static function signatures have changed with respect to their button parameters, which are now used to set the standard buttons and the default button.

Static functions are available for creating information(), question(), warning(), and critical() message boxes.

        QMessageBox.StandardButtons buttons = new QMessageBox.StandardButtons();
        buttons.set(QMessageBox.StandardButton.Save);
        buttons.set(QMessageBox.StandardButton.Discard);
        buttons.set(QMessageBox.StandardButton.Cancel);
        QMessageBox.StandardButton ret = QMessageBox.warning(this, tr("My Application"),
                          tr("The document has been modified.\n"
                             + "Do you want to save your changes?"),
                             buttons, QMessageBox.StandardButton.Save);
The Standard Dialogs example shows how to use QMessageBox and the other built-in Qt dialogs.

Advanced Usage

If the standard buttons are not flexible enough for your message box, you can use the
addButton() overload that takes a text and a ButtonRoleto to add custom buttons. The ButtonRole is used by QMessageBox to determine the ordering of the buttons on screen (which varies according to the platform). You can test the value of clickedButton() after calling exec(). For example,
        QMessageBox msgBox = new QMessageBox();
        QPushButton connectButton = msgBox.addButton(tr("Connect"), QMessageBox.ButtonRole.ActionRole);
        QPushButton abortButton = msgBox.addButton(QMessageBox.StandardButton.Abort);

        msgBox.exec();

        if (msgBox.clickedButton() == connectButton) {
            // connect
        } else if (msgBox.clickedButton() == abortButton) {
            // abort
        }

Default and Escape Keys

The default button (i.e., the button activated when Enter is pressed) can be specified using
setDefaultButton(). If a default button is not specified, QMessageBox tries to find one based on the button roles of the buttons used in the message box.

The escape button (the button activated when Esc is pressed) can be specified using setEscapeButton(). If an escape button is not specified, QMessageBox tries to find one using these rules:

  1. If there is only one button, it is the button activated when Esc is pressed.
  2. If there is a Cancel button, it is the button activated when Esc is pressed.
  3. If there is exactly one button having either the Reject role or the the No role , it is the button activated when Esc is pressed.
When an escape button can't be determined using these rules, pressing Esc has no effect.

See also:
QDialogButtonBox, GUI Design Handbook: Message Box, Standard Dialogs Example, and Application Example.


Nested Class Summary
static class QMessageBox.ButtonRole
          This enum describes the roles that can be used to describe buttons in the button box.
static class QMessageBox.Icon
          This enum has the following values.
static class QMessageBox.StandardButton
          These enums describe flags for standard buttons.
static class QMessageBox.StandardButtons
           
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QDialog
QDialog.DialogCode
 
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.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 QSignalEmitter.Signal1 buttonClicked
          This signal takes 1 generic argument(s).
 
Fields inherited from class com.trolltech.qt.gui.QDialog
accepted, finished, rejected
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QMessageBox()
          Constructs a message box with no text and no buttons.
QMessageBox(QMessageBox.Icon icon, java.lang.String title, java.lang.String text)
          Constructs a message box with the given icon, title, text, and standard buttons.
QMessageBox(QMessageBox.Icon icon, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons)
          Constructs a message box with the given icon, title, text, and standard buttons.
QMessageBox(QMessageBox.Icon icon, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons, QWidget parent)
          Constructs a message box with the given icon, title, text, and standard buttons.
QMessageBox(QMessageBox.Icon icon, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons, QWidget parent, Qt.WindowFlags flags)
          Constructs a message box with the given icon, title, text, and standard buttons.
QMessageBox(QMessageBox.Icon icon, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons, QWidget parent, Qt.WindowType[] flags)
          This is an overloaded method provided for convenience.
QMessageBox(QWidget parent)
          Constructs a message box with no text and no buttons.
 
Method Summary
static void about(QWidget parent, java.lang.String title, java.lang.String text)
          Displays a simple about box with title title and text text.
static void aboutQt(QWidget parent)
          Displays a simple message box about Qt, with the given title and centered over parent (if parent is not 0).
static void aboutQt(QWidget parent, java.lang.String title)
          Displays a simple message box about Qt, with the given title and centered over parent (if parent is not 0).
 void addButton(QAbstractButton button, QMessageBox.ButtonRole role)
          Adds the given button to the message box with the specified role.
 QPushButton addButton(QMessageBox.StandardButton button)
          This is an overloaded member function, provided for convenience.
 QPushButton addButton(java.lang.String text, QMessageBox.ButtonRole role)
          This is an overloaded member function, provided for convenience.
 QAbstractButton button(QMessageBox.StandardButton which)
          Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn't exist in this message box.
 QMessageBox.ButtonRole buttonRole(QAbstractButton button)
          Returns the button role for the specified button.
 java.util.List buttons()
          Returns a list of all the buttons that have been added to the message box.
 QAbstractButton clickedButton()
          Returns the button that was clicked by the user, or 0 if the user hit the Esc key and no escape button was set.
static QMessageBox.StandardButton critical(QWidget parent, java.lang.String title, java.lang.String text)
          Opens a critical message box with the specified title and text.
static QMessageBox.StandardButton critical(QWidget parent, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons)
          Opens a critical message box with the specified title and text.
static QMessageBox.StandardButton critical(QWidget parent, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons, QMessageBox.StandardButton defaultButton)
          Opens a critical message box with the specified title and text.
 QPushButton defaultButton()
          Returns the button that should be the message box's default button.
 java.lang.String detailedText()
          This property holds the text to be displayed in the details area.
 QAbstractButton escapeButton()
          Returns the button that is activated when escape is pressed.
 QMessageBox.Icon icon()
          This property holds the message box's icon.
 QPixmap iconPixmap()
          This property holds the current icon.
static QMessageBox.StandardButton information(QWidget parent, java.lang.String title, java.lang.String text)
          Opens an information message box with the specified title and text.
static QMessageBox.StandardButton information(QWidget parent, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons)
          Opens an information message box with the specified title and text.
static QMessageBox.StandardButton information(QWidget parent, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons, QMessageBox.StandardButton defaultButton)
          Opens an information message box with the specified title and text.
 java.lang.String informativeText()
          This property holds the informative text that provides a fuller description for the message.
static QMessageBox.StandardButton question(QWidget parent, java.lang.String title, java.lang.String text)
          Opens a question message box with the specified title and text.
static QMessageBox.StandardButton question(QWidget parent, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons)
          Opens a question message box with the specified title and text.
static QMessageBox.StandardButton question(QWidget parent, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons, QMessageBox.StandardButton defaultButton)
          Opens a question message box with the specified title and text.
 void removeButton(QAbstractButton button)
          Removes button from the button box without deleting it.
 void setDefaultButton(QMessageBox.StandardButton button)
          Sets the message box's default button to button.
 void setDefaultButton(QPushButton button)
          Sets the message box's default button to button.
 void setDetailedText(java.lang.String text)
          This property holds the text to be displayed in the details area.
 void setEscapeButton(QAbstractButton button)
          Sets the button that gets activated when the Escape key is pressed to button.
 void setEscapeButton(QMessageBox.StandardButton button)
          Sets the buttons that gets activated when the Escape key is pressed to button.
 void setIcon(QMessageBox.Icon arg__1)
          This property holds the message box's icon.
 void setIconPixmap(QPixmap pixmap)
          This property holds the current icon.
 void setInformativeText(java.lang.String text)
          This property holds the informative text that provides a fuller description for the message.
 void setStandardButtons(QMessageBox.StandardButton[] buttons)
          This is an overloaded method provided for convenience.
 void setStandardButtons(QMessageBox.StandardButtons buttons)
          This property holds collection of standard buttons in the message box.
 void setText(java.lang.String text)
          This property holds the message box text to be displayed.
 void setTextFormat(Qt.TextFormat format)
          This property holds the format of the text displayed by the message box.
 QMessageBox.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.
 QMessageBox.StandardButtons standardButtons()
          This property holds collection of standard buttons in the message box.
 java.lang.String text()
          This property holds the message box text to be displayed.
 Qt.TextFormat textFormat()
          This property holds the format of the text displayed by the message box.
static QMessageBox.StandardButton warning(QWidget parent, java.lang.String title, java.lang.String text)
          Opens a warning message box with the specified title and text.
static QMessageBox.StandardButton warning(QWidget parent, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons)
          Opens a warning message box with the specified title and text.
static QMessageBox.StandardButton warning(QWidget parent, java.lang.String title, java.lang.String text, QMessageBox.StandardButtons buttons, QMessageBox.StandardButton defaultButton)
          Opens a warning message box with the specified title and text.
 
Methods inherited from class com.trolltech.qt.gui.QDialog
accept, done, exec, isSizeGripEnabled, open, reject, result, setModal, setResult, setSizeGripEnabled
 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, changeEvent, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuEvent, contextMenuPolicy, cursor, depth, destroy, destroy, destroy, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, effectiveWinId, ensurePolished, enterEvent, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, graphicsProxyWidget, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isMaximized, isMinimized, isModal, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyPressEvent, keyReleaseEvent, languageChange, 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, nativeParentWidget, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, paintEngine, paintEvent, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, 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, setWindowFilePath, 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, windowFilePath, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

buttonClicked

public final QSignalEmitter.Signal1 buttonClicked

This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QAbstractButton(named: button)>:

This signal is emitted whenever a button is clicked inside the QMessageBox. The button that was clicked in returned in button.

Constructor Detail

QMessageBox

public QMessageBox(QMessageBox.Icon icon,
                   java.lang.String title,
                   java.lang.String text,
                   QMessageBox.StandardButtons buttons,
                   QWidget parent,
                   Qt.WindowType[] flags)
This is an overloaded method provided for convenience.


QMessageBox

public QMessageBox(QMessageBox.Icon icon,
                   java.lang.String title,
                   java.lang.String text,
                   QMessageBox.StandardButtons buttons,
                   QWidget parent)
Constructs a message box with the given icon, title, text, and standard buttons. Standard or custom buttons can be added at any time using addButton(). The parent and f arguments are passed to the QDialog constructor.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

On Mac OS X, if parent is not 0 and you want your message box to appear as a Qt::Sheet of that parent, set the message box's window modality to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog.

See also:
setWindowTitle(), setText(), setIcon(), and setStandardButtons().


QMessageBox

public QMessageBox(QMessageBox.Icon icon,
                   java.lang.String title,
                   java.lang.String text,
                   QMessageBox.StandardButtons buttons)
Constructs a message box with the given icon, title, text, and standard buttons. Standard or custom buttons can be added at any time using addButton(). The parent and f arguments are passed to the QDialog constructor.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

On Mac OS X, if parent is not 0 and you want your message box to appear as a Qt::Sheet of that parent, set the message box's window modality to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog.

See also:
setWindowTitle(), setText(), setIcon(), and setStandardButtons().


QMessageBox

public QMessageBox(QMessageBox.Icon icon,
                   java.lang.String title,
                   java.lang.String text)
Constructs a message box with the given icon, title, text, and standard buttons. Standard or custom buttons can be added at any time using addButton(). The parent and f arguments are passed to the QDialog constructor.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

On Mac OS X, if parent is not 0 and you want your message box to appear as a Qt::Sheet of that parent, set the message box's window modality to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog.

See also:
setWindowTitle(), setText(), setIcon(), and setStandardButtons().


QMessageBox

public QMessageBox(QMessageBox.Icon icon,
                   java.lang.String title,
                   java.lang.String text,
                   QMessageBox.StandardButtons buttons,
                   QWidget parent,
                   Qt.WindowFlags flags)
Constructs a message box with the given icon, title, text, and standard buttons. Standard or custom buttons can be added at any time using addButton(). The parent and f arguments are passed to the QDialog constructor.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

On Mac OS X, if parent is not 0 and you want your message box to appear as a Qt::Sheet of that parent, set the message box's window modality to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog.

See also:
setWindowTitle(), setText(), setIcon(), and setStandardButtons().


QMessageBox

public QMessageBox()
Constructs a message box with no text and no buttons. parent is passed to the QDialog constructor.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

On Mac OS X, if parent is not 0 and you want your message box to appear as a Qt::Sheet of that parent, set the message box's window modality to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog.


QMessageBox

public QMessageBox(QWidget parent)
Constructs a message box with no text and no buttons. parent is passed to the QDialog constructor.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

On Mac OS X, if parent is not 0 and you want your message box to appear as a Qt::Sheet of that parent, set the message box's window modality to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog.

Method Detail

addButton

public final void addButton(QAbstractButton button,
                            QMessageBox.ButtonRole role)
Adds the given button to the message box with the specified role.

See also:
removeButton(), button(), and setStandardButtons().


addButton

public final QPushButton addButton(QMessageBox.StandardButton button)
This is an overloaded member function, provided for convenience.

Adds a standard button to the message box if it is valid to do so, and returns the push button.

See also:
setStandardButtons().


addButton

public final QPushButton addButton(java.lang.String text,
                                   QMessageBox.ButtonRole role)
This is an overloaded member function, provided for convenience.

Creates a button with the given text, adds it to the message box for the specified role, and returns it.


button

public final QAbstractButton button(QMessageBox.StandardButton which)
Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn't exist in this message box.

See also:
standardButtons, and standardButton().


buttonRole

public final QMessageBox.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 message box.

See also:
buttons(), and addButton().


buttons

public final java.util.List buttons()
Returns a list of all the buttons that have been added to the message box.

See also:
buttonRole(), addButton(), and removeButton().


clickedButton

public final QAbstractButton clickedButton()
Returns the button that was clicked by the user, or 0 if the user hit the Esc key and no escape button was set.

If exec() hasn't been called yet, returns 0.

Example:

        QMessageBox messageBox = new QMessageBox(this);
        QAbstractButton disconnectButton =
              messageBox.addButton(tr("Disconnect"), QMessageBox.ButtonRole.ActionRole);
        // ...
        messageBox.exec();
        if (messageBox.clickedButton() == disconnectButton) {
           // ...
        }

See also:
standardButton(), and button().


defaultButton

public final QPushButton defaultButton()
Returns the button that should be the message box's default button. Returns 0 if no default button was set.

See also:
setDefaultButton(), addButton(), and QPushButton::setDefault().


detailedText

public final java.lang.String detailedText()
This property holds the text to be displayed in the details area. The text will be interpreted as a plain text.

By default, this property contains an empty string.

See also:
QMessageBox::text, and QMessageBox::informativeText.


escapeButton

public final QAbstractButton escapeButton()
Returns the button that is activated when escape is pressed.

By default, QMessageBox attempts to automatically detect an escape button as follows:

  1. If there is only one button, it is made the escape button.
  2. If there is a Cancel button, it is made the escape button.
  3. On Mac OS X only, if there is exactly one button with the role QMessageBox::RejectRole , it is made the escape button.
When an escape button could not be automatically detected, pressing Esc has no effect.

See also:
setEscapeButton(), and addButton().


icon

public final QMessageBox.Icon icon()
This property holds the message box's icon. The icon of the message box can be specified with one of the values: The default is QMessageBox::NoIcon .

The pixmap used to display the actual icon depends on the current GUI style. You can also set a custom pixmap for the icon by setting the icon pixmap property.

See also:
iconPixmap.


iconPixmap

public final QPixmap iconPixmap()
This property holds the current icon. The icon currently used by the message box. Note that it's often hard to draw one pixmap that looks appropriate in all GUI styles; you may want to supply a different pixmap for each platform.

By default, this property is undefined.

See also:
icon.


informativeText

public final java.lang.String informativeText()
This property holds the informative text that provides a fuller description for the message. Infromative text can be used to expand upon the text() to give more information to the user. On the Mac, this text appears in small system font below the text(). On other platforms, it is simply appended to the existing text.

By default, this property contains an empty string.

See also:
QMessageBox::text, and QMessageBox::detailedText.


removeButton

public final void removeButton(QAbstractButton button)
Removes button from the button box without deleting it.

See also:
addButton(), and setStandardButtons().


setDefaultButton

public final void setDefaultButton(QMessageBox.StandardButton button)
Sets the message box's default button to button.

See also:
addButton(), and QPushButton::setDefault().


setDefaultButton

public final void setDefaultButton(QPushButton button)
Sets the message box's default button to button.

See also:
defaultButton(), addButton(), and QPushButton::setDefault().


setDetailedText

public final void setDetailedText(java.lang.String text)
This property holds the text to be displayed in the details area. The text will be interpreted as a plain text.

By default, this property contains an empty string.

See also:
QMessageBox::text, and QMessageBox::informativeText.


setEscapeButton

public final void setEscapeButton(QAbstractButton button)
Sets the button that gets activated when the Escape key is pressed to button.

See also:
escapeButton(), addButton(), and clickedButton().


setEscapeButton

public final void setEscapeButton(QMessageBox.StandardButton button)
Sets the buttons that gets activated when the Escape key is pressed to button.

See also:
addButton(), and clickedButton().


setIcon

public final void setIcon(QMessageBox.Icon arg__1)
This property holds the message box's icon. The icon of the message box can be specified with one of the values: The default is QMessageBox::NoIcon .

The pixmap used to display the actual icon depends on the current GUI style. You can also set a custom pixmap for the icon by setting the icon pixmap property.

See also:
iconPixmap.


setIconPixmap

public final void setIconPixmap(QPixmap pixmap)
This property holds the current icon. The icon currently used by the message box. Note that it's often hard to draw one pixmap that looks appropriate in all GUI styles; you may want to supply a different pixmap for each platform.

By default, this property is undefined.

See also:
icon.


setInformativeText

public final void setInformativeText(java.lang.String text)
This property holds the informative text that provides a fuller description for the message. Infromative text can be used to expand upon the text() to give more information to the user. On the Mac, this text appears in small system font below the text(). On other platforms, it is simply appended to the existing text.

By default, this property contains an empty string.

See also:
QMessageBox::text, and QMessageBox::detailedText.


setStandardButtons

public final void setStandardButtons(QMessageBox.StandardButton[] buttons)
This is an overloaded method provided for convenience.


setStandardButtons

public final void setStandardButtons(QMessageBox.StandardButtons buttons)
This property holds collection of standard buttons in the message box. This property controls which standard buttons are used by the message box.

By default, this property contains no standard buttons.

See also:
addButton().


setText

public final void setText(java.lang.String text)
This property holds the message box text to be displayed. The text will be interpreted either as a plain text or as rich text, depending on the text format setting (QMessageBox::textFormat). The default setting is Qt::AutoText , i.e., the message box will try to auto-detect the format of the text.

The default value of this property is an empty string.

See also:
textFormat, QMessageBox::informativeText, and QMessageBox::detailedText.


setTextFormat

public final void setTextFormat(Qt.TextFormat format)
This property holds the format of the text displayed by the message box. The current text format used by the message box. See the Qt::TextFormat enum for an explanation of the possible options.

The default format is Qt::AutoText .

See also:
setText().


standardButton

public final QMessageBox.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(), and standardButtons().


standardButtons

public final QMessageBox.StandardButtons standardButtons()
This property holds collection of standard buttons in the message box. This property controls which standard buttons are used by the message box.

By default, this property contains no standard buttons.

See also:
addButton().


text

public final java.lang.String text()
This property holds the message box text to be displayed. The text will be interpreted either as a plain text or as rich text, depending on the text format setting (QMessageBox::textFormat). The default setting is Qt::AutoText , i.e., the message box will try to auto-detect the format of the text.

The default value of this property is an empty string.

See also:
textFormat, QMessageBox::informativeText, and QMessageBox::detailedText.


textFormat

public final Qt.TextFormat textFormat()
This property holds the format of the text displayed by the message box. The current text format used by the message box. See the Qt::TextFormat enum for an explanation of the possible options.

The default format is Qt::AutoText .

See also:
setText().


about

public static void about(QWidget parent,
                         java.lang.String title,
                         java.lang.String text)
Displays a simple about box with title title and text text. The about box's parent is parent.

about() looks for a suitable icon in four locations:

  1. It prefers parent->icon() if that exists.
  2. If not, it tries the top-level widget containing parent.
  3. If that fails, it tries the active window.
  4. As a last resort it uses the Information icon.
The about box has a single button labelled "OK". On Mac OS X, the about box is popped up as a modeless window; on other platforms, it is currently a window modal.

See also:
QWidget::windowIcon(), and QApplication::activeWindow().


aboutQt

public static void aboutQt(QWidget parent)
Displays a simple message box about Qt, with the given title and centered over parent (if parent is not 0). The message includes the version number of Qt being used by the application.

This is useful for inclusion in the Help menu of an application, as shown in the Menus example.

QApplication provides this functionality as a slot.

On Mac OS X, the about box is popped up as a modeless window; on other platforms, it is currently window modal.

See also:
QApplication::aboutQt().


aboutQt

public static void aboutQt(QWidget parent,
                           java.lang.String title)
Displays a simple message box about Qt, with the given title and centered over parent (if parent is not 0). The message includes the version number of Qt being used by the application.

This is useful for inclusion in the Help menu of an application, as shown in the Menus example.

QApplication provides this functionality as a slot.

On Mac OS X, the about box is popped up as a modeless window; on other platforms, it is currently window modal.

See also:
QApplication::aboutQt().


critical

public static QMessageBox.StandardButton critical(QWidget parent,
                                                  java.lang.String title,
                                                  java.lang.String text,
                                                  QMessageBox.StandardButtons buttons)
Opens a critical message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QMessageBox constructors.

See also:
question(), warning(), and information().


critical

public static QMessageBox.StandardButton critical(QWidget parent,
                                                  java.lang.String title,
                                                  java.lang.String text)
Opens a critical message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QMessageBox constructors.

See also:
question(), warning(), and information().


critical

public static QMessageBox.StandardButton critical(QWidget parent,
                                                  java.lang.String title,
                                                  java.lang.String text,
                                                  QMessageBox.StandardButtons buttons,
                                                  QMessageBox.StandardButton defaultButton)
Opens a critical message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QMessageBox constructors.

See also:
question(), warning(), and information().


information

public static QMessageBox.StandardButton information(QWidget parent,
                                                     java.lang.String title,
                                                     java.lang.String text,
                                                     QMessageBox.StandardButtons buttons)
Opens an information message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
question(), warning(), and critical().


information

public static QMessageBox.StandardButton information(QWidget parent,
                                                     java.lang.String title,
                                                     java.lang.String text)
Opens an information message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
question(), warning(), and critical().


information

public static QMessageBox.StandardButton information(QWidget parent,
                                                     java.lang.String title,
                                                     java.lang.String text,
                                                     QMessageBox.StandardButtons buttons,
                                                     QMessageBox.StandardButton defaultButton)
Opens an information message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
question(), warning(), and critical().


question

public static QMessageBox.StandardButton question(QWidget parent,
                                                  java.lang.String title,
                                                  java.lang.String text,
                                                  QMessageBox.StandardButtons buttons)
Opens a question message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
information(), warning(), and critical().


question

public static QMessageBox.StandardButton question(QWidget parent,
                                                  java.lang.String title,
                                                  java.lang.String text)
Opens a question message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
information(), warning(), and critical().


question

public static QMessageBox.StandardButton question(QWidget parent,
                                                  java.lang.String title,
                                                  java.lang.String text,
                                                  QMessageBox.StandardButtons buttons,
                                                  QMessageBox.StandardButton defaultButton)
Opens a question message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
information(), warning(), and critical().


warning

public static QMessageBox.StandardButton warning(QWidget parent,
                                                 java.lang.String title,
                                                 java.lang.String text,
                                                 QMessageBox.StandardButtons buttons)
Opens a warning message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
question(), information(), and critical().


warning

public static QMessageBox.StandardButton warning(QWidget parent,
                                                 java.lang.String title,
                                                 java.lang.String text)
Opens a warning message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
question(), information(), and critical().


warning

public static QMessageBox.StandardButton warning(QWidget parent,
                                                 java.lang.String title,
                                                 java.lang.String text,
                                                 QMessageBox.StandardButtons buttons,
                                                 QMessageBox.StandardButton defaultButton)
Opens a warning message box with the specified title and text. The standard buttons are added to the message box. defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.

Returns the identity of the standard button that was clicked. If Esc was pressed instead, the escape button is returned.

If parent is 0, the message box is an application modal dialog box. If parent is a widget, the message box is window modal relative to parent.

See also:
question(), information(), and critical().