Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Static Public Functions | Protected Functions | Properties | List of all members
QMessageBox Class Reference

The QMessageBox class provides a modal dialog for informing the user or for asking the user a question and receiving an answer. More...

#include <qmessagebox.h>

Inheritance diagram for QMessageBox:
QDialog QWidget QObject QPaintDevice

Public Types

typedef StandardButton Button
 Use QMessageBox::StandardButton instead. More...
 
enum  ButtonRole {
  InvalidRole = -1, AcceptRole, RejectRole, DestructiveRole,
  ActionRole, HelpRole, YesRole, NoRole,
  ResetRole, ApplyRole, NRoles
}
 Combinations of these roles are as flags used to describe different aspects of their behavior. More...
 
enum  Icon {
  NoIcon = 0, Information = 1, Warning = 2, Critical = 3,
  Question = 4
}
 This enum has the following values: More...
 
enum  StandardButton {
  NoButton = 0x00000000, Ok = 0x00000400, Save = 0x00000800, SaveAll = 0x00001000,
  Open = 0x00002000, Yes = 0x00004000, YesToAll = 0x00008000, No = 0x00010000,
  NoToAll = 0x00020000, Abort = 0x00040000, Retry = 0x00080000, Ignore = 0x00100000,
  Close = 0x00200000, Cancel = 0x00400000, Discard = 0x00800000, Help = 0x01000000,
  Apply = 0x02000000, Reset = 0x04000000, RestoreDefaults = 0x08000000, FirstButton = Ok,
  LastButton = RestoreDefaults, YesAll = YesToAll, NoAll = NoToAll, Default = 0x00000100,
  Escape = 0x00000200, FlagMask = 0x00000300, ButtonMask = ~FlagMask
}
 These enums describe flags for standard buttons. More...
 
- Public Types inherited from QDialog
enum  DialogCode { Rejected, Accepted }
 The value returned by a modal dialog. More...
 
- Public Types inherited from QWidget
enum  RenderFlag { DrawWindowBackground = 0x1, DrawChildren = 0x2, IgnoreMask = 0x4 }
 This enum describes how to render the widget when calling QWidget::render(). More...
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 

Public Slots

int exec ()
 Shows the message box as a modal dialog, blocking until the user closes it. More...
 
- Public Slots inherited from QDialog
virtual void accept ()
 Hides the modal dialog and sets the result code to Accepted. More...
 
virtual void done (int)
 Closes the dialog and sets its result code to r. More...
 
int exec ()
 Shows the dialog as a modal dialog, blocking until the user closes it. More...
 
void open ()
 Shows the dialog as a window modal dialog, returning immediately. More...
 
virtual void reject ()
 Hides the modal dialog and sets the result code to Rejected. More...
 
void showExtension (bool)
 If showIt is true, the dialog's extension is shown; otherwise the extension is hidden. More...
 
- Public Slots inherited from QWidget
bool close ()
 Closes this widget. More...
 
void hide ()
 Hides the widget. More...
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack. More...
 
void raise ()
 Raises this widget to the top of the parent widget's stack. More...
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden. More...
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events. More...
 
void setEnabled (bool)
 
void setFocus ()
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden). More...
 
QT_MOC_COMPAT void setShown (bool shown)
 Use setVisible(shown) instead. More...
 
void setStyleSheet (const QString &styleSheet)
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void show ()
 Shows the widget and its child widgets. More...
 
void showFullScreen ()
 Shows the widget in full-screen mode. More...
 
void showMaximized ()
 Shows the widget maximized. More...
 
void showMinimized ()
 Shows the widget minimized, as an icon. More...
 
void showNormal ()
 Restores the widget after it has been maximized or minimized. More...
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void buttonClicked (QAbstractButton *button)
 This signal is emitted whenever a button is clicked inside the QMessageBox. More...
 
- Signals inherited from QDialog
void accepted ()
 This signal is emitted when the dialog has been accepted either by the user or by calling accept() or done() with the QDialog::Accepted argument. More...
 
void finished (int result)
 This signal is emitted when the dialog's result code has been set, either by the user or by calling done(), accept(), or reject(). More...
 
void rejected ()
 This signal is emitted when the dialog has been rejected either by the user or by calling reject() or done() with the QDialog::Rejected argument. More...
 
- Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void addButton (QAbstractButton *button, ButtonRole role)
 Adds the given button to the message box with the specified role. More...
 
QPushButtonaddButton (const QString &text, ButtonRole role)
 Creates a button with the given text, adds it to the message box for the specified role, and returns it. More...
 
QPushButtonaddButton (StandardButton button)
 Adds a standard button to the message box if it is valid to do so, and returns the push button. More...
 
QAbstractButtonbutton (StandardButton which) const
 Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn't exist in this message box. More...
 
ButtonRole buttonRole (QAbstractButton *button) const
 Returns the button role for the specified button. More...
 
QList< QAbstractButton * > buttons () const
 Returns a list of all the buttons that have been added to the message box. More...
 
QString buttonText (int button) const
 Returns the text of the message box button button, or an empty string if the message box does not contain the button. More...
 
QAbstractButtonclickedButton () const
 Returns the button that was clicked by the user, or 0 if the user hit the Esc key and no escape button was set. More...
 
QPushButtondefaultButton () const
 Returns the button that should be the message box's default button. More...
 
QString detailedText () const
 
QAbstractButtonescapeButton () const
 Returns the button that is activated when escape is pressed. More...
 
Icon icon () const
 
QPixmap iconPixmap () const
 
QString informativeText () const
 
void open (QObject *receiver, const char *member)
 Opens the dialog and connects its finished() or buttonClicked() signal to the slot specified by receiver and member. More...
 
 QMessageBox (QWidget *parent=0)
 Constructs a message box with no text and no buttons. More...
 
 QMessageBox (Icon icon, const QString &title, const QString &text, StandardButtons buttons=NoButton, QWidget *parent=0, Qt::WindowFlags flags=Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint)
 Constructs a message box with the given icon, title, text, and standard buttons. More...
 
 QMessageBox (const QString &title, const QString &text, Icon icon, int button0, int button1, int button2, QWidget *parent=0, Qt::WindowFlags f=Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint)
 Constructs a message box with a title, a text, an icon, and up to three buttons. More...
 
void removeButton (QAbstractButton *button)
 Removes button from the button box without deleting it. More...
 
void setButtonText (int button, const QString &text)
 Sets the text of the message box button button to text. More...
 
void setDefaultButton (QPushButton *button)
 Sets the message box's default button to button. More...
 
void setDefaultButton (StandardButton button)
 Sets the message box's default button to button. More...
 
void setDetailedText (const QString &text)
 
void setEscapeButton (QAbstractButton *button)
 Sets the button that gets activated when the Escape key is pressed to button. More...
 
void setEscapeButton (StandardButton button)
 Sets the buttons that gets activated when the Escape key is pressed to button. More...
 
void setIcon (Icon)
 
void setIconPixmap (const QPixmap &pixmap)
 
void setInformativeText (const QString &text)
 
void setStandardButtons (StandardButtons buttons)
 
void setText (const QString &text)
 
void setTextFormat (Qt::TextFormat format)
 
void setVisible (bool visible)
 Reimplemented Function More...
 
void setWindowModality (Qt::WindowModality windowModality)
 This function shadows QWidget::setWindowModality(). More...
 
void setWindowTitle (const QString &title)
 This function shadows QWidget::setWindowTitle(). More...
 
QSize sizeHint () const
 
StandardButton standardButton (QAbstractButton *button) const
 Returns the standard button enum value corresponding to the given button, or NoButton if the given button isn't a standard button. More...
 
StandardButtons standardButtons () const
 
QString text () const
 
Qt::TextFormat textFormat () const
 
 ~QMessageBox ()
 Destroys the message box. More...
 
- Public Functions inherited from QDialog
QWidgetextension () const
 Returns the dialog's extension or 0 if no extension has been defined. More...
 
bool isSizeGripEnabled () const
 
QSize minimumSizeHint () const
 Reimplemented Function More...
 
Qt::Orientation orientation () const
 Returns the dialog's extension orientation. More...
 
 QDialog (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a dialog with parent parent. More...
 
int result () const
 In general returns the modal dialog's result code, Accepted or Rejected. More...
 
void setExtension (QWidget *extension)
 Sets the widget, extension, to be the dialog's extension, deleting any previous extension. More...
 
void setModal (bool modal)
 
void setOrientation (Qt::Orientation orientation)
 If orientation is Qt::Horizontal, the extension will be displayed to the right of the dialog's main area. More...
 
void setResult (int r)
 Sets the modal dialog's result code to i. More...
 
void setSizeGripEnabled (bool)
 
 ~QDialog ()
 Destroys the QDialog, deleting all its children. More...
 
- Public Functions inherited from QWidget
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions. More...
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window. More...
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions. More...
 
void addActions (QList< QAction *> actions)
 Appends the actions actions to this widget's list of actions. More...
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents. More...
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget. More...
 
QSize baseSize () const
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system. More...
 
QWidgetchildAt (const QPoint &p) const
 Returns the visible child widget at point p in the widget's own coordinate system. More...
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 Takes keyboard input focus from the widget. More...
 
void clearMask ()
 Removes any mask set by setMask(). More...
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins. More...
 
QRect contentsRect () const
 Returns the area inside the widget's margins. More...
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void createWinId ()
 
QCursor cursor () const
 
int devType () const
 
WId effectiveWinId () const
 Returns the effective window system identifier of the widget, i. More...
 
void ensurePolished () const
 Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette). More...
 
Qt::FocusPolicy focusPolicy () const
 
QWidgetfocusProxy () const
 Returns the focus proxy, or 0 if there is no focus proxy. More...
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on. More...
 
const QFontfont () const
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font. More...
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font. More...
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role. More...
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the widget's contents margins for left, top, right, and bottom. More...
 
HDC getDC () const
 Returns the window system handle of the widget, for low-level access. More...
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags. More...
 
void grabKeyboard ()
 Grabs the keyboard input. More...
 
void grabMouse ()
 Grabs the mouse input. More...
 
void grabMouse (const QCursor &)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context. More...
 
QGraphicsEffectgraphicsEffect () const
 The graphicsEffect function returns a pointer to the widget's graphics effect. More...
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns 0. More...
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w. More...
 
QInputContextinputContext ()
 This function returns the QInputContext for this widget. More...
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery) const
 This method is only relevant for input widgets. More...
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before. More...
 
void insertActions (QAction *before, QList< QAction *> actions)
 Inserts the actions actions to this widget's list of actions, before the action before. More...
 
WId internalWinId () const
 Returns the window system identifier of the widget, or 0 if the widget is not created yet. More...
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child, and both widgets are within the same window; otherwise returns false. More...
 
bool isEnabled () const
 
bool isEnabledTo (QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false. More...
 
bool isEnabledToTLW () const
 This function is deprecated. More...
 
bool isFullScreen () const
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false. More...
 
bool isLeftToRight () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isRightToLeft () const
 
bool isTopLevel () const
 Use isWindow() instead. More...
 
bool isVisible () const
 
bool isVisibleTo (QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false. More...
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false. More...
 
bool isWindowModified () const
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed. More...
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
Qt::HANDLE macCGHandle () const
 Returns the CoreGraphics handle of the widget. More...
 
Qt::HANDLE macQDHandle () const
 Returns the QuickDraw handle of the widget. More...
 
QPoint mapFrom (QWidget *, const QPoint &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system. More...
 
QPoint mapFromGlobal (const QPoint &) const
 Translates the global screen coordinate pos to widget coordinates. More...
 
QPoint mapFromParent (const QPoint &) const
 Translates the parent widget coordinate pos to widget coordinates. More...
 
QPoint mapTo (QWidget *, const QPoint &) const
 Translates the widget coordinate pos to the coordinate system of parent. More...
 
QPoint mapToGlobal (const QPoint &) const
 Translates the widget coordinate pos to global screen coordinates. More...
 
QPoint mapToParent (const QPoint &) const
 Translates the widget coordinate pos to a coordinate in the parent widget. More...
 
QRegion mask () const
 Returns the mask currently set on a widget. More...
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (int x, int y)
 This corresponds to move(QPoint(x, y)). More...
 
void move (const QPoint &)
 
QWidgetnativeParentWidget () const
 Returns the native parent for this widget, i. More...
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain. More...
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system. More...
 
void overrideWindowState (Qt::WindowStates state)
 
QPaintEnginepaintEngine () const
 Returns the widget's paint engine. More...
 
const QPalettepalette () const
 
QWidgetparentWidget () const
 Returns the parent of this widget, or 0 if it does not have any parent widget. More...
 
QPoint pos () const
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain. More...
 
 QWidget (QWidget *parent=0, Qt::WindowFlags f=0)
 Constructs a widget which is a child of parent, with widget flags set to f. More...
 
QRect rect () const
 
void releaseDC (HDC) const
 Releases the HDC hdc acquired by a previous call to getDC(). More...
 
void releaseKeyboard ()
 Releases the keyboard grab. More...
 
void releaseMouse ()
 Releases the mouse grab. More...
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system. More...
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions. More...
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the sourceRegion of this widget into the target using renderFlags to determine how to render. More...
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 Renders the widget into the painter's QPainter::device(). More...
 
void repaint (int x, int y, int w, int h)
 This version repaints a rectangle (x, y, w, h) inside the widget. More...
 
void repaint (const QRect &)
 This version repaints a rectangle rect inside the widget. More...
 
void repaint (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void resize (int w, int h)
 This corresponds to resize(QSize(w, h)). More...
 
void resize (const QSize &)
 
bool restoreGeometry (const QByteArray &geometry)
 Restores the geometry and state top-level widgets stored in the byte array geometry. More...
 
QByteArray saveGeometry () const
 Saves the current geometry and state for top-level widgets. More...
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward. More...
 
void scroll (int dx, int dy, const QRect &)
 This version only scrolls r and does not move the children of the widget. More...
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. More...
 
void setAutoFillBackground (bool enabled)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role. More...
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 This corresponds to setBaseSize(QSize(basew, baseh)). More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom. More...
 
void setContentsMargins (const QMargins &margins)
 The setContentsMargins function sets the margins around the widget's contents. More...
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &)
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths. More...
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking. More...
 
void setFixedSize (int w, int h)
 Sets the width of the widget to w and the height to h. More...
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights. More...
 
void setFocus (Qt::FocusReason reason)
 Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window. More...
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w. More...
 
void setFont (const QFont &)
 Use the single-argument overload instead. More...
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role. More...
 
void setGeometry (int x, int y, int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This corresponds to setGeometry(QRect(x, y, w, h)). More...
 
void setGeometry (const QRect &)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 The setGraphicsEffect function is for setting the widget's graphics effect. More...
 
void setInputContext (QInputContext *)
 This function sets the input context context on this widget. More...
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout. More...
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. More...
 
void setMask (const QRegion &)
 Causes only the parts of the widget which overlap region to be visible. More...
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This function corresponds to setMaximumSize(QSize(maxw, maxh)). More...
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This function corresponds to setMinimumSize(QSize(minw, minh)). More...
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &)
 Use the single-argument overload instead. More...
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags. More...
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This function also takes widget flags, f as an argument. More...
 
void setShortcutAutoRepeat (int id, bool enable=true)
 If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled. More...
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled. More...
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (int w, int h)
 Sets the x (width) size increment to w and the y (height) size increment to h. More...
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width. More...
 
void setStatusTip (const QString &)
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style. More...
 
void setToolTip (const QString &)
 
void setUpdatesEnabled (bool enable)
 
void setupUi (QWidget *widget)
 Sets up the user interface for the specified widget. More...
 
void setWhatsThis (const QString &)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags type)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowIconText (const QString &)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &)
 Sets the window's role to role. More...
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState. More...
 
void setWindowSurface (QWindowSurface *surface)
 Sets the window surface to be the surface specified. More...
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack. More...
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false. More...
 
QString toolTip () const
 
QWidgettopLevelWidget () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false. More...
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type. More...
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (int x, int y, int w, int h)
 This version updates a rectangle (x, y, w, h) inside the widget. More...
 
void update (const QRect &)
 This version updates a rectangle rect inside the widget. More...
 
void update (const QRegion &)
 This version repaints a region rgn inside the widget. More...
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry. More...
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur. More...
 
QString whatsThis () const
 
int width () const
 
QWidgetwindow () const
 Returns the window for this widget, i.e. More...
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e. More...
 
QIcon windowIcon () const
 
QString windowIconText () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 Returns the window's role, or an empty string. More...
 
Qt::WindowStates windowState () const
 Returns the current window state. More...
 
QWindowSurfacewindowSurface () const
 Returns the QWindowSurface this widget will be drawn into. More...
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 Returns the window type of this widget. More...
 
WId winId () const
 Returns the window system identifier of the widget. More...
 
int x () const
 
const QX11Infox11Info () const
 Returns information about the configuration of the X display used to display the widget. More...
 
Qt::HANDLE x11PictureHandle () const
 Returns the X11 Picture handle of the widget for XRender support. More...
 
int y () const
 
 ~QWidget ()
 Destroys the widget. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Static Public Functions

static void about (QWidget *parent, const QString &title, const QString &text)
 Displays a simple about box with title title and text text. More...
 
static void aboutQt (QWidget *parent, const QString &title=QString())
 Displays a simple message box about Qt, with the given title and centered over parent (if parent is not 0). More...
 
static StandardButton critical (QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
 Opens a critical message box with the given title and text in front of the specified parent widget. More...
 
static int critical (QWidget *parent, const QString &title, const QString &text, int button0, int button1, int button2=0)
 Opens a critical message box with the given title and text. More...
 
static int critical (QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text=QString(), const QString &button2Text=QString(), int defaultButtonNumber=0, int escapeButtonNumber=-1)
 Displays a critical error message box with the given title and text, as well as one, two, or three buttons. More...
 
static int critical (QWidget *parent, const QString &title, const QString &text, StandardButton button0, StandardButton button1)
 
static StandardButton information (QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
 Opens an information message box with the given title and text in front of the specified parent widget. More...
 
static int information (QWidget *parent, const QString &title, const QString &text, int button0, int button1=0, int button2=0)
 Opens an information message box with the given title and the text. More...
 
static int information (QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text=QString(), const QString &button2Text=QString(), int defaultButtonNumber=0, int escapeButtonNumber=-1)
 Displays an information message box with the given title and text, as well as one, two or three buttons. More...
 
static StandardButton information (QWidget *parent, const QString &title, const QString &text, StandardButton button0, StandardButton button1=NoButton)
 
static StandardButton question (QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
 Opens a question message box with the given title and text in front of the specified parent widget. More...
 
static int question (QWidget *parent, const QString &title, const QString &text, int button0, int button1=0, int button2=0)
 Opens a question message box with the given title and text. More...
 
static int question (QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text=QString(), const QString &button2Text=QString(), int defaultButtonNumber=0, int escapeButtonNumber=-1)
 Displays a question message box with the given title and text, as well as one, two or three buttons. More...
 
static int question (QWidget *parent, const QString &title, const QString &text, StandardButton button0, StandardButton button1)
 
static QPixmap standardIcon (Icon icon)
 Returns the pixmap used for a standard icon. More...
 
static StandardButton warning (QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
 Opens a warning message box with the given title and text in front of the specified parent widget. More...
 
static int warning (QWidget *parent, const QString &title, const QString &text, int button0, int button1, int button2=0)
 Opens a warning message box with the given title and text. More...
 
static int warning (QWidget *parent, const QString &title, const QString &text, const QString &button0Text, const QString &button1Text=QString(), const QString &button2Text=QString(), int defaultButtonNumber=0, int escapeButtonNumber=-1)
 Displays a warning message box with the given title and text, as well as one, two, or three buttons. More...
 
static int warning (QWidget *parent, const QString &title, const QString &text, StandardButton button0, StandardButton button1)
 
- Static Public Functions inherited from QWidget
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifer/handle id. More...
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input. More...
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input. More...
 
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 

Protected Functions

void changeEvent (QEvent *event)
 Reimplemented Function More...
 
void closeEvent (QCloseEvent *event)
 Reimplemented Function More...
 
bool event (QEvent *e)
 Reimplemented Function More...
 
void keyPressEvent (QKeyEvent *event)
 Reimplemented Function More...
 
void resizeEvent (QResizeEvent *event)
 Reimplemented Function More...
 
void showEvent (QShowEvent *event)
 Reimplemented Function More...
 
- Protected Functions inherited from QDialog
void adjustPosition (QWidget *)
 
void contextMenuEvent (QContextMenuEvent *)
 Reimplemented Function More...
 
bool eventFilter (QObject *, QEvent *)
 Reimplemented Function More...
 
 QDialog (QDialogPrivate &, QWidget *parent, Qt::WindowFlags f=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
- Protected Functions inherited from QWidget
virtual void actionEvent (QActionEvent *)
 This event handler is called with the given event whenever the widget's actions are changed. More...
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window if window is 0, otherwise sets the widget's window to window. More...
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources. More...
 
virtual void dragEnterEvent (QDragEnterEvent *)
 This event handler is called when a drag is in progress and the mouse enters this widget. More...
 
virtual void dragLeaveEvent (QDragLeaveEvent *)
 This event handler is called when a drag is in progress and the mouse leaves this widget. More...
 
virtual void dragMoveEvent (QDragMoveEvent *)
 This event handler is called if a drag is in progress, and when any of the following conditions occur: the cursor enters this widget, the cursor moves within this widget, or a modifier key is pressed on the keyboard while this widget has the focus. More...
 
virtual void dropEvent (QDropEvent *)
 This event handler is called when the drag is dropped on this widget. More...
 
virtual void enabledChange (bool)
 
virtual void enterEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter. More...
 
bool event (QEvent *)
 This is the main event handler; it handles event event. More...
 
virtual void focusInEvent (QFocusEvent *)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget. More...
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual bool focusNextPrevChild (bool next)
 Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void focusOutEvent (QFocusEvent *)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget. More...
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for Shift+Tab, and returns true if it can find a new widget, or false if it can't. More...
 
virtual void fontChange (const QFont &)
 
virtual void hideEvent (QHideEvent *)
 This event handler can be reimplemented in a subclass to receive widget hide events. More...
 
virtual void inputMethodEvent (QInputMethodEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive Input Method composition events. More...
 
virtual void keyReleaseEvent (QKeyEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget. More...
 
virtual void languageChange ()
 
virtual void leaveEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter. More...
 
virtual bool macEvent (EventHandlerCallRef, EventRef)
 This special event handler can be reimplemented in a subclass to receive native Macintosh events. More...
 
int metric (PaintDeviceMetric) const
 Internal implementation of the virtual QPaintDevice::metric() function. More...
 
virtual void mouseDoubleClickEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget. More...
 
virtual void mouseMoveEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget. More...
 
virtual void mousePressEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget. More...
 
virtual void mouseReleaseEvent (QMouseEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse release events for the widget. More...
 
virtual void moveEvent (QMoveEvent *)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter. More...
 
virtual void paintEvent (QPaintEvent *)
 This event handler can be reimplemented in a subclass to receive paint events passed in event. More...
 
virtual void paletteChange (const QPalette &)
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
virtual bool qwsEvent (QWSEvent *)
 This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux events which are passed in the event parameter. More...
 
void resetInputContext ()
 This function can be called on the widget that currently has focus to reset the input method operating on it. More...
 
virtual void styleChange (QStyle &)
 
virtual void tabletEvent (QTabletEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive tablet events for the widget. More...
 
virtual void wheelEvent (QWheelEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive wheel events for the widget. More...
 
virtual void windowActivationChange (bool)
 
virtual bool winEvent (MSG *message, long *result)
 This special event handler can be reimplemented in a subclass to receive native Windows events which are passed in the message parameter. More...
 
virtual bool x11Event (XEvent *)
 This special event handler can be reimplemented in a subclass to receive native X11 events passed in the event parameter. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

QString detailedText
 the text to be displayed in the details area. More...
 
Icon icon
 the message box's icon More...
 
QPixmap iconPixmap
 the current icon More...
 
QString informativeText
 the informative text that provides a fuller description for the message More...
 
StandardButtons standardButtons
 collection of standard buttons in the message box More...
 
QString text
 the message box text to be displayed. More...
 
Qt::TextFormat textFormat
 the format of the text displayed by the message box More...
 

Additional Inherited Members

- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 Updates the widget's micro focus. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QPaintDevice
ushort painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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.

QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.exec();

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.

msgbox1.png

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.

QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
int ret = msgBox.exec();

This is the approach recommended in the Mac OS X Guidelines. Similar guidelines apply for the other platforms, but note the different ways the informative text is handled for different platforms.

msgbox2.png

The exec() slot returns the StandardButtons value of the button that was clicked.

switch (ret) {
// Save was clicked
break;
// Don't Save was clicked
break;
// Cancel was clicked
break;
default:
// should never be reached
break;
}

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.

msgbox3.png

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

msgbox4.png

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:

qmessagebox-quest.png
Question For asking a question during normal operations.
qmessagebox-info.png
Information For reporting information about normal operations.
qmessagebox-warn.png
Warning For reporting non-critical errors.
qmessagebox-crit.png
Critical For reporting critical errors.

Predefined icons are not defined by QMessageBox, but provided by the style. 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 either setIcon() for one of the standard icons, or setIconPixmap() 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.

int ret = QMessageBox::warning(this, tr("My Application"),
tr("The document has been modified.\n"
"Do you want to save your changes?"),

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;
QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
QPushButton *abortButton = msgBox.addButton(QMessageBox::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, {fowler}{GUI Design Handbook: Message Box}, {Standard Dialogs Example}, {Application Example}

Definition at line 59 of file qmessagebox.h.

Typedefs

◆ Button

Use QMessageBox::StandardButton instead.

Definition at line 133 of file qmessagebox.h.

Enumerations

◆ ButtonRole

Combinations of these roles are as flags used to describe different aspects of their behavior.

  • InvalidRole The button is invalid.
  • AcceptRole Clicking the button causes the dialog to be accepted (e.g. OK).
  • RejectRole Clicking the button causes the dialog to be rejected (e.g. Cancel).
  • DestructiveRole Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog.
  • ActionRole Clicking the button causes changes to the elements within the dialog.
  • HelpRole The button can be clicked to request help.
  • YesRole The button is a "Yes"-like button.
  • NoRole The button is a "No"-like button.
  • ApplyRole The button applies current changes.
  • ResetRole The button resets the dialog's fields to default values.
  • NRoles
See also
StandardButton
Enumerator
InvalidRole 
AcceptRole 
RejectRole 
DestructiveRole 
ActionRole 
HelpRole 
YesRole 
NoRole 
ResetRole 
ApplyRole 
NRoles 

Definition at line 84 of file qmessagebox.h.

◆ Icon

This enum has the following values:

  • NoIcon the message box does not have any icon.
  • Question an icon indicating that the message is asking a question.
  • Information an icon indicating that the message is nothing out of the ordinary.
  • Warning an icon indicating that the message is a warning, but can be dealt with.
  • Critical an icon indicating that the message represents a critical problem.
Enumerator
NoIcon 
Information 
Warning 
Critical 
Question 

Definition at line 76 of file qmessagebox.h.

◆ StandardButton

These enums describe flags for standard buttons.

Since
4.2

Each button has a defined ButtonRole .

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

The following values are obsolete:

See also
ButtonRole, standardButtons
Enumerator
NoButton 
Ok 
Save 
SaveAll 
Open 
Yes 
YesToAll 
No 
NoToAll 
Abort 
Retry 
Ignore 
Close 
Cancel 
Discard 
Help 
Apply 
Reset 
RestoreDefaults 
FirstButton 
LastButton 
YesAll 
NoAll 
Default 
Escape 
FlagMask 
ButtonMask 

Definition at line 100 of file qmessagebox.h.

100  {
101  // keep this in sync with QDialogButtonBox::StandardButton
102  NoButton = 0x00000000,
103  Ok = 0x00000400,
104  Save = 0x00000800,
105  SaveAll = 0x00001000,
106  Open = 0x00002000,
107  Yes = 0x00004000,
108  YesToAll = 0x00008000,
109  No = 0x00010000,
110  NoToAll = 0x00020000,
111  Abort = 0x00040000,
112  Retry = 0x00080000,
113  Ignore = 0x00100000,
114  Close = 0x00200000,
115  Cancel = 0x00400000,
116  Discard = 0x00800000,
117  Help = 0x01000000,
118  Apply = 0x02000000,
119  Reset = 0x04000000,
120  RestoreDefaults = 0x08000000,
121 
122  FirstButton = Ok, // internal
123  LastButton = RestoreDefaults, // internal
124 
125  YesAll = YesToAll, // obsolete
126  NoAll = NoToAll, // obsolete
127 
128  Default = 0x00000100, // obsolete
129  Escape = 0x00000200, // obsolete
130  FlagMask = 0x00000300, // obsolete
131  ButtonMask = ~FlagMask // obsolete
132  };

Constructors and Destructors

◆ QMessageBox() [1/3]

QMessageBox::QMessageBox ( QWidget parent = 0)
explicit

Constructs a message box with no text and no buttons.

parent is passed to the QDialog constructor.

On Mac OS X, if you want your message box to appear as a Qt::Sheet of its parent, set the message box's window modality to Qt::WindowModal or use open(). Otherwise, the message box will be a standard dialog.

Definition at line 776 of file qmessagebox.cpp.

Referenced by about(), aboutQt(), and setWindowModality().

778 {
779  Q_D(QMessageBox);
780  d->init();
781 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
QDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a dialog with parent parent.
Definition: qdialog.cpp:268

◆ QMessageBox() [2/3]

QMessageBox::QMessageBox ( Icon  icon,
const QString title,
const QString text,
StandardButtons  buttons = NoButton,
QWidget parent = 0,
Qt::WindowFlags  f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint 
)

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.

The message box is an application modal dialog box.

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(), setStandardButtons()

Definition at line 799 of file qmessagebox.cpp.

803 {
804  Q_D(QMessageBox);
805  d->init(title, text);
806  setIcon(icon);
807  if (buttons != NoButton)
809 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
QList< QAbstractButton * > buttons() const
Returns a list of all the buttons that have been added to the message box.
#define Q_D(Class)
Definition: qglobal.h:2482
QDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a dialog with parent parent.
Definition: qdialog.cpp:268
void setStandardButtons(StandardButtons buttons)
void setIcon(Icon)
Icon icon() const

◆ ~QMessageBox()

QMessageBox::~QMessageBox ( )

Destroys the message box.

Definition at line 814 of file qmessagebox.cpp.

815 {
816 }

◆ QMessageBox() [3/3]

QMessageBox::QMessageBox ( const QString title,
const QString text,
Icon  icon,
int  button0,
int  button1,
int  button2,
QWidget parent = 0,
Qt::WindowFlags  f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint 
)

Constructs a message box with a title, a text, an icon, and up to three buttons.

The icon must be one of the following:

Each button, button0, button1 and button2, can have one of the following values:

Use QMessageBox::NoButton for the later parameters to have fewer than three buttons in your message box. If you don't specify any buttons at all, QMessageBox will provide an Ok button.

One of the buttons can be OR-ed with the QMessageBox::Default flag to make it the default button (clicked when Enter is pressed).

One of the buttons can be OR-ed with the QMessageBox::Escape flag to make it the cancel or close button (clicked when Esc is pressed).

QMessageBox mb("Application Name",
"Hardware failure.\n\nDisk error detected\nDo you want to stop?",
if (mb.exec() == QMessageBox::No) {
// try again

The message box is an application modal dialog box.

The parent and f arguments are passed to the QDialog constructor.

See also
setWindowTitle(), setText(), setIcon()

Definition at line 2093 of file qmessagebox.cpp.

2096  : QDialog(*new QMessageBoxPrivate, parent,
2097  f /*| Qt::MSWindowsFixedSizeDialogHint #### */| Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
2098 {
2099  Q_D(QMessageBox);
2100  d->init(title, text);
2101  setIcon(icon);
2102  d->addOldButtons(button0, button1, button2);
2103 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
QDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a dialog with parent parent.
Definition: qdialog.cpp:268
void setIcon(Icon)
Icon icon() const

Functions

◆ about()

void QMessageBox::about ( QWidget parent,
const QString title,
const QString text 
)
static

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 application modal.

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

Definition at line 1773 of file qmessagebox.cpp.

1774 {
1775 #ifdef Q_WS_MAC
1776  static QPointer<QMessageBox> oldMsgBox;
1777 
1778  if (oldMsgBox && oldMsgBox->text() == text) {
1779  oldMsgBox->show();
1780  oldMsgBox->raise();
1781  oldMsgBox->activateWindow();
1782  return;
1783  }
1784 #endif
1785 
1786  QMessageBox *msgBox = new QMessageBox(title, text, Information, 0, 0, 0, parent
1787 #ifdef Q_WS_MAC
1789 #endif
1790  );
1792  QIcon icon = msgBox->windowIcon();
1793  QSize size = icon.actualSize(QSize(64, 64));
1794  msgBox->setIconPixmap(icon.pixmap(size));
1795 
1796  // should perhaps be a style hint
1797 #ifdef Q_WS_MAC
1798  oldMsgBox = msgBox;
1799 #if 0
1800  // ### doesn't work until close button is enabled in title bar
1801  msgBox->d_func()->autoAddOkButton = false;
1802 #else
1803  msgBox->d_func()->buttonBox->setCenterButtons(true);
1804 #endif
1805  msgBox->show();
1806 #else
1807  msgBox->exec();
1808 #endif
1809 }
QSize size() const
QMessageBox(QWidget *parent=0)
Constructs a message box with no text and no buttons.
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
QString text() const
The QPointer class is a template class that provides guarded pointers to QObject. ...
Definition: qpointer.h:54
QString text
the message box text to be displayed.
Definition: qmessagebox.h:64
QIcon windowIcon() const
void setIconPixmap(const QPixmap &pixmap)
void raise()
Raises this widget to the top of the parent widget&#39;s stack.
Definition: qwidget.cpp:11901
void show()
Shows the widget and its child widgets.
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
Definition: qicon.cpp:730
int exec()
Shows the message box as a modal dialog, blocking until the user closes it.
void activateWindow()
Sets the top-level widget containing this widget to be the active window.
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
Definition: qicon.cpp:693
Icon icon() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ aboutQt()

void QMessageBox::aboutQt ( QWidget parent,
const QString title = QString() 
)
static

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 application modal.

See also
QApplication::aboutQt()

Definition at line 1826 of file qmessagebox.cpp.

Referenced by QApplication::aboutQt(), and QApplicationPrivate::globalEventProcessor().

1827 {
1828 #ifdef Q_WS_MAC
1829  static QPointer<QMessageBox> oldMsgBox;
1830 
1831  if (oldMsgBox) {
1832  oldMsgBox->show();
1833  oldMsgBox->raise();
1834  oldMsgBox->activateWindow();
1835  return;
1836  }
1837 #endif
1838 
1839  QString translatedTextAboutQtCaption;
1840  translatedTextAboutQtCaption = QMessageBox::tr(
1841  "<h3>About Qt</h3>"
1842  "<p>This program uses Qt version %1.</p>"
1844  QString translatedTextAboutQtText;
1845  translatedTextAboutQtText = QMessageBox::tr(
1846  "<p>Qt is a C++ toolkit for cross-platform application "
1847  "development.</p>"
1848  "<p>Qt provides single-source portability across MS&nbsp;Windows, "
1849  "Mac&nbsp;OS&nbsp;X, Linux, and all major commercial Unix variants. "
1850  "Qt is also available for embedded devices as Qt for Embedded Linux "
1851  "and Qt for Windows CE.</p>"
1852  "<p>Qt is available under three different licensing options designed "
1853  "to accommodate the needs of our various users.</p>"
1854  "<p>Qt licensed under our commercial license agreement is appropriate "
1855  "for development of proprietary/commercial software where you do not "
1856  "want to share any source code with third parties or otherwise cannot "
1857  "comply with the terms of the GNU LGPL version 2.1 or GNU GPL version "
1858  "3.0.</p>"
1859  "<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the "
1860  "development of Qt applications (proprietary or open source) provided "
1861  "you can comply with the terms and conditions of the GNU LGPL version "
1862  "2.1.</p>"
1863  "<p>Qt licensed under the GNU General Public License version 3.0 is "
1864  "appropriate for the development of Qt applications where you wish to "
1865  "use such applications in combination with software subject to the "
1866  "terms of the GNU GPL version 3.0 or where you are otherwise willing "
1867  "to comply with the terms of the GNU GPL version 3.0.</p>"
1868  "<p>Please see <a href=\"http://qt.digia.com/product/licensing\">qt.digia.com/product/licensing</a> "
1869  "for an overview of Qt licensing.</p>"
1870  "<p>Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).</p>"
1871  "<p>Qt is a Digia product. See <a href=\"http://qt.digia.com/\">qt.digia.com</a> "
1872  "for more information.</p>"
1873  );
1874  QMessageBox *msgBox = new QMessageBox(parent);
1876  msgBox->setWindowTitle(title.isEmpty() ? tr("About Qt") : title);
1877  msgBox->setText(translatedTextAboutQtCaption);
1878  msgBox->setInformativeText(translatedTextAboutQtText);
1879 
1880  QPixmap pm(QLatin1String(":/trolltech/qmessagebox/images/qtlogo-64.png"));
1881  if (!pm.isNull())
1882  msgBox->setIconPixmap(pm);
1883 #if defined(Q_WS_WINCE)
1884  msgBox->setDefaultButton(msgBox->addButton(QMessageBox::Ok));
1885 #endif
1886 
1887  // should perhaps be a style hint
1888 #ifdef Q_WS_MAC
1889  oldMsgBox = msgBox;
1890 #if 0
1891  // ### doesn't work until close button is enabled in title bar
1892  msgBox->d_func()->autoAddOkButton = false;
1893 #else
1894  msgBox->d_func()->buttonBox->setCenterButtons(true);
1895 #endif
1896  msgBox->show();
1897 #else
1898  msgBox->exec();
1899 #endif
1900 }
QMessageBox(QWidget *parent=0)
Constructs a message box with no text and no buttons.
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QPointer class is a template class that provides guarded pointers to QObject. ...
Definition: qpointer.h:54
void setIconPixmap(const QPixmap &pixmap)
void addButton(QAbstractButton *button, ButtonRole role)
Adds the given button to the message box with the specified role.
void raise()
Raises this widget to the top of the parent widget&#39;s stack.
Definition: qwidget.cpp:11901
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setText(const QString &text)
#define QT_VERSION_STR
This macro expands to a string that specifies Qt&#39;s version number (for example, "4.
Definition: qglobal.h:47
void show()
Shows the widget and its child widgets.
void setInformativeText(const QString &text)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int exec()
Shows the message box as a modal dialog, blocking until the user closes it.
void setDefaultButton(QPushButton *button)
Sets the message box&#39;s default button to button.
void activateWindow()
Sets the top-level widget containing this widget to be the active window.
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void setWindowTitle(const QString &title)
This function shadows QWidget::setWindowTitle().

◆ addButton() [1/3]

void QMessageBox::addButton ( QAbstractButton button,
ButtonRole  role 
)

Adds the given button to the message box with the specified role.

Since
4.2
See also
removeButton(), button(), setStandardButtons()

Definition at line 829 of file qmessagebox.cpp.

Referenced by aboutQt(), addButton(), setButtonText(), showEvent(), showNewMessageBox(), and QMessageBoxPrivate::showOldMessageBox().

830 {
831  Q_D(QMessageBox);
832  if (!button)
833  return;
834  removeButton(button);
835  d->buttonBox->addButton(button, (QDialogButtonBox::ButtonRole)role);
836  d->customButtonList.append(button);
837  d->autoAddOkButton = false;
838 }
void removeButton(QAbstractButton *button)
Removes button from the button box without deleting it.
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
ButtonRole
This enum describes the roles that can be used to describe buttons in the button box.

◆ addButton() [2/3]

QPushButton * QMessageBox::addButton ( const QString text,
ButtonRole  role 
)

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

Since
4.2 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 850 of file qmessagebox.cpp.

851 {
852  Q_D(QMessageBox);
853  QPushButton *pushButton = new QPushButton(text);
854  addButton(pushButton, role);
855  d->updateSize();
856  return pushButton;
857 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
void addButton(QAbstractButton *button, ButtonRole role)
Adds the given button to the message box with the specified role.
friend class QPushButton
Definition: qdialog.h:59

◆ addButton() [3/3]

QPushButton * QMessageBox::addButton ( StandardButton  button)

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

Since
4.2 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
See also
setStandardButtons()

Definition at line 871 of file qmessagebox.cpp.

872 {
873  Q_D(QMessageBox);
874  QPushButton *pushButton = d->buttonBox->addButton((QDialogButtonBox::StandardButton)button);
875  if (pushButton)
876  d->autoAddOkButton = false;
877  return pushButton;
878 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton * button(StandardButton which) const
Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn&#39;t exi...
StandardButton
These enums describe flags for standard buttons.

◆ button()

QAbstractButton * QMessageBox::button ( StandardButton  which) const

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

Since
4.2
See also
standardButtons, standardButton()

Definition at line 964 of file qmessagebox.cpp.

Referenced by QMessageBoxPrivate::findButton(), setDefaultButton(), and showNewMessageBox().

965 {
966  Q_D(const QMessageBox);
967  return d->buttonBox->button(QDialogButtonBox::StandardButton(which));
968 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
StandardButton
These enums describe flags for standard buttons.

◆ buttonClicked

void QMessageBox::buttonClicked ( QAbstractButton button)
signal

This signal is emitted whenever a button is clicked inside the QMessageBox.

The button that was clicked in returned in button.

Referenced by open().

◆ buttonRole()

QMessageBox::ButtonRole QMessageBox::buttonRole ( QAbstractButton button) const

Returns the button role for the specified button.

Since
4.5

This function returns InvalidRole if button is 0 or has not been added to the message box.

See also
buttons(), addButton()

Definition at line 1534 of file qmessagebox.cpp.

1535 {
1536  Q_D(const QMessageBox);
1537  return QMessageBox::ButtonRole(d->buttonBox->buttonRole(button));
1538 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
ButtonRole
Combinations of these roles are as flags used to describe different aspects of their behavior...
Definition: qmessagebox.h:84

◆ buttons()

QList< QAbstractButton * > QMessageBox::buttons ( ) const

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

Since
4.5
See also
buttonRole(), addButton(), removeButton()

Definition at line 1517 of file qmessagebox.cpp.

Referenced by QMessageBoxPrivate::detectEscapeButton(), and keyPressEvent().

1518 {
1519  Q_D(const QMessageBox);
1520  return d->buttonBox->buttons();
1521 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482

◆ buttonText()

QString QMessageBox::buttonText ( int  button) const

Returns the text of the message box button button, or an empty string if the message box does not contain the button.

Use button() and QPushButton::text() instead.

Definition at line 2484 of file qmessagebox.cpp.

2485 {
2486  Q_D(const QMessageBox);
2487 
2488  if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {
2489  return abstractButton->text();
2490  } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {
2491  // for compatibility with Qt 4.0/4.1
2492  return QDialogButtonBox::tr("OK");
2493  }
2494  return QString();
2495 }
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton * button(StandardButton which) const
Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn&#39;t exi...

◆ changeEvent()

void QMessageBox::changeEvent ( QEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1375 of file qmessagebox.cpp.

1376 {
1377  Q_D(QMessageBox);
1378  switch (ev->type()) {
1379  case QEvent::StyleChange:
1380  {
1381  if (d->icon != NoIcon)
1382  setIcon(d->icon);
1383  Qt::TextInteractionFlags flags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this));
1384  d->label->setTextInteractionFlags(flags);
1385  d->buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this));
1386  if (d->informativeLabel)
1387  d->informativeLabel->setTextInteractionFlags(flags);
1388  // intentional fall through
1389  }
1390  case QEvent::FontChange:
1392 #ifdef Q_WS_MAC
1393  {
1394  QFont f = font();
1395  f.setBold(true);
1396  d->label->setFont(f);
1397  }
1398 #endif
1399  default:
1400  break;
1401  }
1403 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
void setBold(bool)
If enable is true sets the font&#39;s weight to QFont::Bold ; otherwise sets the weight to QFont::Normal...
Definition: qfont.h:352
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
const char * styleHint(const QFontDef &request)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void setIcon(Icon)
const QFont & font() const

◆ clickedButton()

QAbstractButton * QMessageBox::clickedButton ( ) const

Returns the button that was clicked by the user, or 0 if the user hit the Esc key and no escape button was set.

Since
4.2

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

Example:

QMessageBox messageBox(this);
QAbstractButton *disconnectButton =
messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole);
...
messageBox.exec();
if (messageBox.clickedButton() == disconnectButton) {
...
}
See also
standardButton(), button()

Definition at line 1096 of file qmessagebox.cpp.

Referenced by showNewMessageBox().

1097 {
1098  Q_D(const QMessageBox);
1099  return d->clickedButton;
1100 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482

◆ closeEvent()

void QMessageBox::closeEvent ( QCloseEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1360 of file qmessagebox.cpp.

1361 {
1362  Q_D(QMessageBox);
1363  if (!d->detectedEscapeButton) {
1364  e->ignore();
1365  return;
1366  }
1368  d->clickedButton = d->detectedEscapeButton;
1369  setResult(d->execReturnCode(d->detectedEscapeButton));
1370 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
void closeEvent(QCloseEvent *)
Reimplemented Function
Definition: qdialog.cpp:733
void setResult(int r)
Sets the modal dialog&#39;s result code to i.
Definition: qdialog.cpp:475

◆ critical() [1/4]

QMessageBox::StandardButton QMessageBox::critical ( QWidget parent,
const QString title,
const QString text,
StandardButtons  buttons = Ok,
StandardButton  defaultButton = NoButton 
)
static

Opens a critical message box with the given title and text in front of the specified parent widget.

Since
4.2

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 Default and Escape Keys {escape button} is returned.

The message box is an application modal dialog box.

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(), information()

Definition at line 1745 of file qmessagebox.cpp.

1748 {
1749  return showNewMessageBox(parent, Critical, title, text, buttons, defaultButton);
1750 }
QList< QAbstractButton * > buttons() const
Returns a list of all the buttons that have been added to the message box.
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QPushButton * defaultButton() const
Returns the button that should be the message box&#39;s default button.

◆ critical() [2/4]

int QMessageBox::critical ( QWidget parent,
const QString title,
const QString text,
int  button0,
int  button1,
int  button2 = 0 
)
static

Opens a critical message box with the given title and text.

The dialog may have up to three buttons. Each of the button parameters, button0, button1 and button2 may be set to one of the following values:

If you don't want all three buttons, set the last button, or last two buttons to QMessageBox::NoButton.

One button can be OR-ed with QMessageBox::Default, and one button can be OR-ed with QMessageBox::Escape.

Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.) of the button that was clicked.

The message box is an application modal dialog box.

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
information(), question(), warning()

Definition at line 2423 of file qmessagebox.cpp.

2425 {
2426  return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text,
2427  button0, button1, button2);
2428 }
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)

◆ critical() [3/4]

int QMessageBox::critical ( QWidget parent,
const QString title,
const QString text,
const QString button0Text,
const QString button1Text = QString(),
const QString button2Text = QString(),
int  defaultButtonNumber = 0,
int  escapeButtonNumber = -1 
)
static

Displays a critical error message box with the given title and text, as well as one, two, or three buttons.

button0Text is the text of the first button, and is optional. If button0Text is not supplied, "OK" (translated) will be used. button1Text is the text of the second button, and is optional, and button2Text is the text of the third button, and is optional. defaultButtonNumber (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). escapeButtonNumber is the index of the Escape button; pressing Escape is the same as clicking this button. It defaults to -1; supply 0, 1, or 2 to make pressing Escape equivalent to clicking the relevant button.

The message box is an application modal dialog box.

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
information(), question(), warning()

Definition at line 2462 of file qmessagebox.cpp.

2466 {
2467  return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text,
2468  button0Text, button1Text, button2Text,
2469  defaultButtonNumber, escapeButtonNumber);
2470 }
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)

◆ critical() [4/4]

int QMessageBox::critical ( QWidget parent,
const QString title,
const QString text,
StandardButton  button0,
StandardButton  button1 
)
inlinestatic

Definition at line 272 of file qmessagebox.h.

275  { return critical(parent, title, text, StandardButtons(button0), button1); }
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens a critical message box with the given title and text in front of the specified parent widget...

◆ defaultButton()

QPushButton * QMessageBox::defaultButton ( ) const

Returns the button that should be the message box's default button.

Since
4.2

Returns 0 if no default button was set.

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

Definition at line 1114 of file qmessagebox.cpp.

Referenced by setWindowModality(), and showNewMessageBox().

1115 {
1116  Q_D(const QMessageBox);
1117  return d->defaultButton;
1118 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482

◆ detailedText()

QString QMessageBox::detailedText ( ) const

Referenced by setButtonText().

◆ escapeButton()

QAbstractButton * QMessageBox::escapeButton ( ) const

Returns the button that is activated when escape is pressed.

Since
4.2

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
addButton()

Definition at line 993 of file qmessagebox.cpp.

Referenced by QMessageBoxPrivate::detectEscapeButton().

994 {
995  Q_D(const QMessageBox);
996  return d->escapeButton;
997 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482

◆ event()

bool QMessageBox::event ( QEvent e)
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1315 of file qmessagebox.cpp.

1316 {
1317  bool result =QDialog::event(e);
1318  switch (e->type()) {
1319  case QEvent::LayoutRequest:
1320  d_func()->updateSize();
1321  break;
1323  d_func()->retranslateStrings();
1324  break;
1325 #ifdef Q_WS_WINCE
1326  case QEvent::OkRequest:
1327  case QEvent::HelpRequest: {
1328  QString bName =
1329  (e->type() == QEvent::OkRequest)
1330  ? QApplication::translate("QMessageBox", "OK")
1331  : QApplication::translate("QMessageBox", "Help");
1332  QList<QPushButton*> list = findChildren<QPushButton*>();
1333  for (int i=0; i<list.size(); ++i) {
1334  QPushButton *pb = list.at(i);
1335  if (pb->text() == bName) {
1336  if (pb->isEnabled())
1337  pb->click();
1338  return pb->isEnabled();
1339  }
1340  }
1341  }
1342 #endif
1343  default:
1344  break;
1345  }
1346  return result;
1347 }
QString text() const
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isEnabled() const
Definition: qwidget.h:948
int result() const
In general returns the modal dialog&#39;s result code, Accepted or Rejected.
Definition: qdialog.cpp:458
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool event(QEvent *e)
Reimplemented Function
Definition: qdialog.cpp:426
void click()
Performs a click.
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ exec

int QMessageBox::exec ( )
slot

Shows the message box as a modal dialog, blocking until the user closes it.

When using a QMessageBox with standard buttons, this functions returns a StandardButton value indicating the standard button that was clicked. When using QMessageBox with custom buttons, this function returns an opaque value; use clickedButton() to determine which button was clicked.

Note
The result() function returns also StandardButton value instead of QDialog::DialogCode

Users cannot interact with any other window in the same application until they close the dialog, either by clicking a button or by using a mechanism provided by the window system.

See also
show(), result()

Referenced by about(), aboutQt(), showNewMessageBox(), and QMessageBoxPrivate::showOldMessageBox().

◆ icon()

Icon QMessageBox::icon ( ) const

◆ iconPixmap()

QPixmap QMessageBox::iconPixmap ( ) const

Referenced by setIcon().

◆ information() [1/4]

QMessageBox::StandardButton QMessageBox::information ( QWidget parent,
const QString title,
const QString text,
StandardButtons  buttons = Ok,
StandardButton  defaultButton = NoButton 
)
static

Opens an information message box with the given title and text in front of the specified parent widget.

Since
4.2

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 Default and Escape Keys {escape button} is returned.

The message box is an application modal dialog box.

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(), critical()

Definition at line 1638 of file qmessagebox.cpp.

Referenced by critical(), QFileSystemModel::setData(), and QCoreFuriCuri::timerEvent().

1641 {
1642  return showNewMessageBox(parent, Information, title, text, buttons,
1643  defaultButton);
1644 }
QList< QAbstractButton * > buttons() const
Returns a list of all the buttons that have been added to the message box.
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QPushButton * defaultButton() const
Returns the button that should be the message box&#39;s default button.

◆ information() [2/4]

int QMessageBox::information ( QWidget parent,
const QString title,
const QString text,
int  button0,
int  button1 = 0,
int  button2 = 0 
)
static

Opens an information message box with the given title and the text.

The dialog may have up to three buttons. Each of the buttons, button0, button1 and button2 may be set to one of the following values:

If you don't want all three buttons, set the last button, or last two buttons to QMessageBox::NoButton.

One button can be OR-ed with QMessageBox::Default, and one button can be OR-ed with QMessageBox::Escape.

Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.) of the button that was clicked.

The message box is an application modal dialog box.

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(), critical()

Definition at line 2147 of file qmessagebox.cpp.

2149 {
2150  return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text,
2151  button0, button1, button2);
2152 }
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)

◆ information() [3/4]

int QMessageBox::information ( QWidget parent,
const QString title,
const QString text,
const QString button0Text,
const QString button1Text = QString(),
const QString button2Text = QString(),
int  defaultButtonNumber = 0,
int  escapeButtonNumber = -1 
)
static

Displays an information message box with the given title and text, as well as one, two or three buttons.

button0Text is the text of the first button, and is optional. If button0Text is not supplied, "OK" (translated) will be used. button1Text is the text of the second button, and is optional. button2Text is the text of the third button, and is optional. defaultButtonNumber (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). escapeButtonNumber is the index of the escape button; pressing Esc is the same as clicking this button. It defaults to -1; supply 0, 1 or 2 to make pressing Esc equivalent to clicking the relevant button.

The message box is an application modal dialog box.

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(), critical()

Definition at line 2187 of file qmessagebox.cpp.

2191 {
2192  return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text,
2193  button0Text, button1Text, button2Text,
2194  defaultButtonNumber, escapeButtonNumber);
2195 }
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)

◆ information() [4/4]

int QMessageBox::information ( QWidget parent,
const QString title,
const QString text,
StandardButton  button0,
StandardButton  button1 = NoButton 
)
inlinestatic

Definition at line 227 of file qmessagebox.h.

230  { return information(parent, title, text, StandardButtons(button0), button1); }
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens an information message box with the given title and text in front of the specified parent widge...

◆ informativeText()

QString QMessageBox::informativeText ( ) const

Referenced by setDetailedText().

◆ keyPressEvent()

void QMessageBox::keyPressEvent ( QKeyEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1408 of file qmessagebox.cpp.

1409 {
1410  Q_D(QMessageBox);
1411  if (e->key() == Qt::Key_Escape
1412 #ifdef Q_WS_MAC
1413  || (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period)
1414 #endif
1415  ) {
1416  if (d->detectedEscapeButton) {
1417 #ifdef Q_WS_MAC
1418  d->detectedEscapeButton->animateClick();
1419 #else
1420  d->detectedEscapeButton->click();
1421 #endif
1422  }
1423  return;
1424  }
1425 
1426 #if defined (Q_OS_WIN) && !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT)
1427  if (e == QKeySequence::Copy) {
1428  QString separator = QString::fromLatin1("---------------------------\n");
1429  QString textToCopy = separator;
1430  separator.prepend(QLatin1Char('\n'));
1431  textToCopy += windowTitle() + separator; // title
1432  textToCopy += d->label->text() + separator; // text
1433 
1434  if (d->informativeLabel)
1435  textToCopy += d->informativeLabel->text() + separator;
1436 
1437  QString buttonTexts;
1438  QList<QAbstractButton *> buttons = d->buttonBox->buttons();
1439  for (int i = 0; i < buttons.count(); i++) {
1440  buttonTexts += buttons[i]->text() + QLatin1String(" ");
1441  }
1442  textToCopy += buttonTexts + separator;
1443 
1444  QApplication::clipboard()->setText(textToCopy);
1445  return;
1446  }
1447 #endif //QT_NO_SHORTCUT QT_NO_CLIPBOARD Q_OS_WIN
1448 
1449 #ifndef QT_NO_SHORTCUT
1450  if (!(e->modifiers() & Qt::AltModifier)) {
1451  int key = e->key() & ~((int)Qt::MODIFIER_MASK|(int)Qt::UNICODE_ACCEL);
1452  if (key) {
1453  const QList<QAbstractButton *> buttons = d->buttonBox->buttons();
1454  for (int i = 0; i < buttons.count(); ++i) {
1455  QAbstractButton *pb = buttons.at(i);
1456  int acc = pb->shortcut() & ~((int)Qt::MODIFIER_MASK|(int)Qt::UNICODE_ACCEL);
1457  if (acc == key) {
1458  pb->animateClick();
1459  return;
1460  }
1461  }
1462  }
1463  }
1464 #endif
1466 }
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
double d
Definition: qnumeric_p.h:62
void keyPressEvent(QKeyEvent *)
Reimplemented Function
Definition: qdialog.cpp:695
QString & prepend(QChar c)
Definition: qstring.h:261
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QList< QAbstractButton * > buttons() const
Returns a list of all the buttons that have been added to the message box.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setText(const QString &, Mode mode=Clipboard)
Copies text into the clipboard as plain text.
Definition: qclipboard.cpp:375
#define Q_D(Class)
Definition: qglobal.h:2482
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QString windowTitle() const
QKeySequence shortcut
the mnemonic associated with the button
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int key
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void animateClick(int msec=100)
Performs an animated click: the button is pressed immediately, and released msec milliseconds later (...

◆ open()

void QMessageBox::open ( QObject receiver,
const char *  member 
)

Opens the dialog and connects its finished() or buttonClicked() signal to the slot specified by receiver and member.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

If the slot in member has a pointer for its first parameter the connection is to buttonClicked(), otherwise the connection is to finished().

The signal will be disconnected from the slot when the dialog is closed.

Definition at line 1495 of file qmessagebox.cpp.

1496 {
1497  Q_D(QMessageBox);
1498  const char *signal = member && strchr(member, '*') ? SIGNAL(buttonClicked(QAbstractButton*))
1499  : SIGNAL(finished(int));
1500  connect(this, signal, receiver, member);
1501  d->signalToDisconnectOnClose = signal;
1502  d->receiverToDisconnectOnClose = receiver;
1503  d->memberToDisconnectOnClose = member;
1504  QDialog::open();
1505 }
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
void buttonClicked(QAbstractButton *button)
This signal is emitted whenever a button is clicked inside the QMessageBox.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
void finished(int result)
This signal is emitted when the dialog&#39;s result code has been set, either by the user or by calling d...

◆ question() [1/4]

QMessageBox::StandardButton QMessageBox::question ( QWidget parent,
const QString title,
const QString text,
StandardButtons  buttons = Ok,
StandardButton  defaultButton = NoButton 
)
static

Opens a question message box with the given title and text in front of the specified parent widget.

Since
4.2

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 Default and Escape Keys {escape button} is returned.

The message box is an application modal dialog box.

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
information(), warning(), critical()

Definition at line 1675 of file qmessagebox.cpp.

Referenced by QUnixPrintWidgetPrivate::checkFields().

1678 {
1679  return showNewMessageBox(parent, Question, title, text, buttons, defaultButton);
1680 }
QList< QAbstractButton * > buttons() const
Returns a list of all the buttons that have been added to the message box.
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QPushButton * defaultButton() const
Returns the button that should be the message box&#39;s default button.

◆ question() [2/4]

int QMessageBox::question ( QWidget parent,
const QString title,
const QString text,
int  button0,
int  button1 = 0,
int  button2 = 0 
)
static

Opens a question message box with the given title and text.

The dialog may have up to three buttons. Each of the buttons, button0, button1 and button2 may be set to one of the following values:

If you don't want all three buttons, set the last button, or last two buttons to QMessageBox::NoButton.

One button can be OR-ed with QMessageBox::Default, and one button can be OR-ed with QMessageBox::Escape.

Returns the identity (QMessageBox::Yes, or QMessageBox::No, etc.) of the button that was clicked.

The message box is an application modal dialog box.

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
information(), warning(), critical()

Definition at line 2239 of file qmessagebox.cpp.

2241 {
2242  return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text,
2243  button0, button1, button2);
2244 }
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)

◆ question() [3/4]

int QMessageBox::question ( QWidget parent,
const QString title,
const QString text,
const QString button0Text,
const QString button1Text = QString(),
const QString button2Text = QString(),
int  defaultButtonNumber = 0,
int  escapeButtonNumber = -1 
)
static

Displays a question message box with the given title and text, as well as one, two or three buttons.

button0Text is the text of the first button, and is optional. If button0Text is not supplied, "OK" (translated) will be used. button1Text is the text of the second button, and is optional. button2Text is the text of the third button, and is optional. defaultButtonNumber (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). escapeButtonNumber is the index of the Escape button; pressing Escape is the same as clicking this button. It defaults to -1; supply 0, 1 or 2 to make pressing Escape equivalent to clicking the relevant button.

The message box is an application modal dialog box.

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
information(), warning(), critical()

Definition at line 2278 of file qmessagebox.cpp.

2282 {
2283  return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text,
2284  button0Text, button1Text, button2Text,
2285  defaultButtonNumber, escapeButtonNumber);
2286 }
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)

◆ question() [4/4]

int QMessageBox::question ( QWidget parent,
const QString title,
const QString text,
StandardButton  button0,
StandardButton  button1 
)
inlinestatic
Warning
This function is not part of the public interface.

Needed for Qt 4 source compatibility

Definition at line 242 of file qmessagebox.h.

245  { return question(parent, title, text, StandardButtons(button0), button1); }
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens a question message box with the given title and text in front of the specified parent widget...

◆ removeButton()

void QMessageBox::removeButton ( QAbstractButton button)

Removes button from the button box without deleting it.

Since
4.2
See also
addButton(), setStandardButtons()

Definition at line 890 of file qmessagebox.cpp.

Referenced by addButton(), and setDetailedText().

891 {
892  Q_D(QMessageBox);
893  d->customButtonList.removeAll(button);
894  if (d->escapeButton == button)
895  d->escapeButton = 0;
896  if (d->defaultButton == button)
897  d->defaultButton = 0;
898  d->buttonBox->removeButton(button);
899  d->updateSize();
900 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482

◆ resizeEvent()

void QMessageBox::resizeEvent ( QResizeEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1352 of file qmessagebox.cpp.

1353 {
1354  QDialog::resizeEvent(event);
1355 }
void resizeEvent(QResizeEvent *)
Reimplemented Function
Definition: qdialog.cpp:1268

◆ setButtonText()

void QMessageBox::setButtonText ( int  button,
const QString text 
)

Sets the text of the message box button button to text.

Setting the text of a button that is not in the message box is silently ignored.

Use addButton() instead.

Definition at line 2509 of file qmessagebox.cpp.

2510 {
2511  Q_D(QMessageBox);
2512  if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {
2513  abstractButton->setText(text);
2514  } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {
2515  // for compatibility with Qt 4.0/4.1
2516  addButton(QMessageBox::Ok)->setText(text);
2517  }
2518 }
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
void addButton(QAbstractButton *button, ButtonRole role)
Adds the given button to the message box with the specified role.
QAbstractButton * button(StandardButton which) const
Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn&#39;t exi...

◆ setDefaultButton() [1/2]

void QMessageBox::setDefaultButton ( QPushButton button)

Sets the message box's default button to button.

Since
4.2
See also
addButton(), QPushButton::setDefault()

Definition at line 1131 of file qmessagebox.cpp.

Referenced by aboutQt(), setDefaultButton(), setWindowModality(), showNewMessageBox(), and QMessageBoxPrivate::showOldMessageBox().

1132 {
1133  Q_D(QMessageBox);
1134  if (!d->buttonBox->buttons().contains(button))
1135  return;
1136  d->defaultButton = button;
1137  button->setDefault(true);
1138  button->setFocus();
1139 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
void setDefault(bool)
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton * button(StandardButton which) const
Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn&#39;t exi...
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432

◆ setDefaultButton() [2/2]

void QMessageBox::setDefaultButton ( QMessageBox::StandardButton  button)

Sets the message box's default button to button.

Since
4.3
See also
addButton(), QPushButton::setDefault()

Definition at line 1152 of file qmessagebox.cpp.

1153 {
1154  Q_D(QMessageBox);
1156 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton * button(StandardButton which) const
Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn&#39;t exi...
StandardButton
These enums describe flags for standard buttons.
void setDefaultButton(QPushButton *button)
Sets the message box&#39;s default button to button.

◆ setDetailedText()

void QMessageBox::setDetailedText ( const QString text)

Definition at line 2541 of file qmessagebox.cpp.

2542 {
2543  Q_D(QMessageBox);
2544  if (text.isEmpty()) {
2545  delete d->detailsText;
2546  d->detailsText = 0;
2547  removeButton(d->detailsButton);
2548  delete d->detailsButton;
2549  d->detailsButton = 0;
2550  return;
2551  }
2552 
2553  if (!d->detailsText) {
2554  d->detailsText = new QMessageBoxDetailsText(this);
2556  if (grid)
2557  grid->addWidget(d->detailsText, grid->rowCount(), 0, 1, grid->columnCount());
2558  d->detailsText->hide();
2559  }
2560  if (!d->detailsButton)
2561  d->detailsButton = new DetailButton(this);
2562  d->detailsText->setText(text);
2563 }
void removeButton(QAbstractButton *button)
Removes button from the button box without deleting it.
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_D(Class)
Definition: qglobal.h:2482
int rowCount() const
Returns the number of rows in this grid.
int columnCount() const
Returns the number of columns in this grid.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QGridLayout class lays out widgets in a grid.
Definition: qgridlayout.h:60
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qgridlayout.h:116

◆ setEscapeButton() [1/2]

void QMessageBox::setEscapeButton ( QAbstractButton button)

Sets the button that gets activated when the Escape key is pressed to button.

Since
4.2
See also
addButton(), clickedButton()

Definition at line 1010 of file qmessagebox.cpp.

Referenced by setEscapeButton(), and QMessageBoxPrivate::showOldMessageBox().

1011 {
1012  Q_D(QMessageBox);
1013  if (d->buttonBox->buttons().contains(button))
1014  d->escapeButton = button;
1015 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setEscapeButton() [2/2]

void QMessageBox::setEscapeButton ( QMessageBox::StandardButton  button)

Sets the buttons that gets activated when the Escape key is pressed to button.

Since
4.3
See also
addButton(), clickedButton()

Definition at line 1028 of file qmessagebox.cpp.

1029 {
1030  Q_D(QMessageBox);
1032 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
QAbstractButton * button(StandardButton which) const
Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn&#39;t exi...
StandardButton
These enums describe flags for standard buttons.
void setEscapeButton(QAbstractButton *button)
Sets the button that gets activated when the Escape key is pressed to button.

◆ setIcon()

void QMessageBox::setIcon ( Icon  icon)

Definition at line 1245 of file qmessagebox.cpp.

Referenced by changeEvent(), QMessageBox(), and setWindowModality().

1246 {
1247  Q_D(QMessageBox);
1249  this));
1250  d->icon = icon;
1251 }
double d
Definition: qnumeric_p.h:62
Icon
This enum has the following values:
Definition: qmessagebox.h:76
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
void setIconPixmap(const QPixmap &pixmap)
static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb)
Icon icon() const

◆ setIconPixmap()

void QMessageBox::setIconPixmap ( const QPixmap pixmap)

Definition at line 1276 of file qmessagebox.cpp.

Referenced by about(), aboutQt(), and setIcon().

1277 {
1278  Q_D(QMessageBox);
1279  d->iconLabel->setPixmap(pixmap);
1280  d->updateSize();
1281  d->icon = NoIcon;
1282 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setInformativeText()

void QMessageBox::setInformativeText ( const QString text)

Definition at line 2592 of file qmessagebox.cpp.

Referenced by aboutQt().

2593 {
2594  Q_D(QMessageBox);
2595  if (text.isEmpty()) {
2596  layout()->removeWidget(d->informativeLabel);
2597  delete d->informativeLabel;
2598  d->informativeLabel = 0;
2599 #ifndef Q_WS_MAC
2600  d->label->setContentsMargins(2, 0, 0, 0);
2601 #endif
2602  d->updateSize();
2603  return;
2604  }
2605 
2606  if (!d->informativeLabel) {
2607  QLabel *label = new QLabel(this);
2608  label->setObjectName(QLatin1String("qt_msgbox_informativelabel"));
2609  label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this)));
2611  label->setOpenExternalLinks(true);
2612  label->setWordWrap(true);
2613 #ifndef Q_WS_MAC
2614  d->label->setContentsMargins(2, 0, 0, 0);
2615  label->setContentsMargins(2, 0, 0, 6);
2616  label->setIndent(9);
2617 #else
2618  label->setContentsMargins(16, 0, 0, 0);
2619  // apply a smaller font the information label on the mac
2620  label->setFont(qt_app_fonts_hash()->value("QTipLabel"));
2621 #endif
2622  label->setWordWrap(true);
2623  QGridLayout *grid = static_cast<QGridLayout *>(layout());
2624 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
2625  label->hide();
2626  QTextBrowser *textBrowser = new QTextBrowser(this);
2627  textBrowser->setOpenExternalLinks(true);
2628 #if defined(Q_OS_SYMBIAN)
2629  const int preferredTextColumn = (QApplication::layoutDirection() == Qt::LeftToRight) ? 0 : 1;
2630 #else
2631  const int preferredTextColumn = 1;
2632 #endif
2633  grid->addWidget(textBrowser, 1, preferredTextColumn, 1, 1);
2634  d->textBrowser = textBrowser;
2635 #else
2636  grid->addWidget(label, 1, 1, 1, 1);
2637 #endif
2638  d->informativeLabel = label;
2639  }
2640  d->informativeLabel->setText(text);
2641 
2642 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
2643  //We need to put the informative label inside textBrowser to enable scrolling of long texts.
2644  d->textBrowser->setText(d->informativeLabel->text());
2645 #endif
2646 
2647  d->updateSize();
2648 }
double d
Definition: qnumeric_p.h:62
static Qt::LayoutDirection layoutDirection()
void setFont(const QFont &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4996
void setWordWrap(bool on)
Definition: qlabel.cpp:579
void setOpenExternalLinks(bool open)
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
Definition: qlabel.cpp:820
void setOpenExternalLinks(bool open)
Definition: qlabel.cpp:797
#define Q_D(Class)
Definition: qglobal.h:2482
QStyle * style() const
Definition: qwidget.cpp:2742
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom.
Definition: qwidget.cpp:7449
const char * styleHint(const QFontDef &request)
FontHash * qt_app_fonts_hash()
void hide()
Hides the widget.
Definition: qwidget.h:501
The QGridLayout class lays out widgets in a grid.
Definition: qgridlayout.h:60
The QTextBrowser class provides a rich text browser with hypertext navigation.
Definition: qtextbrowser.h:58
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qgridlayout.h:116
void setAlignment(Qt::Alignment)
Without this function, a call to e.
Definition: qlabel.cpp:532
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
Definition: qlayout.cpp:1516
void setIndent(int)
Definition: qlabel.cpp:620

◆ setStandardButtons()

void QMessageBox::setStandardButtons ( StandardButtons  buttons)

Definition at line 916 of file qmessagebox.cpp.

Referenced by QMessageBox().

917 {
918  Q_D(QMessageBox);
919  d->buttonBox->setStandardButtons(QDialogButtonBox::StandardButtons(int(buttons)));
920 
921  QList<QAbstractButton *> buttonList = d->buttonBox->buttons();
922  if (!buttonList.contains(d->escapeButton))
923  d->escapeButton = 0;
924  if (!buttonList.contains(d->defaultButton))
925  d->defaultButton = 0;
926  d->autoAddOkButton = false;
927  d->updateSize();
928 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
QList< QAbstractButton * > buttons() const
Returns a list of all the buttons that have been added to the message box.
#define Q_D(Class)
Definition: qglobal.h:2482
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
if(void) toggleToolbarShown
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setText()

void QMessageBox::setText ( const QString text)

Definition at line 1180 of file qmessagebox.cpp.

Referenced by aboutQt().

1181 {
1182  Q_D(QMessageBox);
1183  d->label->setText(text);
1184  d->label->setWordWrap(d->label->textFormat() == Qt::RichText
1185  || (d->label->textFormat() == Qt::AutoText && Qt::mightBeRichText(text)));
1186  d->updateSize();
1187 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setTextFormat()

void QMessageBox::setTextFormat ( Qt::TextFormat  format)

Definition at line 1303 of file qmessagebox.cpp.

1304 {
1305  Q_D(QMessageBox);
1306  d->label->setTextFormat(format);
1307  d->label->setWordWrap(format == Qt::RichText
1308  || (format == Qt::AutoText && Qt::mightBeRichText(d->label->text())));
1309  d->updateSize();
1310 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setVisible()

void QMessageBox::setVisible ( bool  visible)
virtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1472 of file qmessagebox.cpp.

1473 {
1474  Q_D(QMessageBox);
1475  if (visible)
1476  d->hideSpecial();
1478 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
bool visible
whether the widget is visible
Definition: qwidget.h:191
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756

◆ setWindowModality()

void QMessageBox::setWindowModality ( Qt::WindowModality  windowModality)

This function shadows QWidget::setWindowModality().

Since
4.2

Sets the modality of the message box to windowModality.

On Mac OS X, if the modality is set to Qt::WindowModal and the message box has a parent, then the message box will be a Qt::Sheet, otherwise the message box will be a standard dialog.

Definition at line 2687 of file qmessagebox.cpp.

2688 {
2690 
2693  else
2695  setDefaultButton(d_func()->defaultButton);
2696 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
Qt::WindowModality windowModality() const
void setWindowModality(Qt::WindowModality windowModality)
Definition: qwidget.cpp:2991
QPushButton * defaultButton() const
Returns the button that should be the message box&#39;s default button.
void setDefaultButton(QPushButton *button)
Sets the message box&#39;s default button to button.

◆ setWindowTitle()

void QMessageBox::setWindowTitle ( const QString title)

This function shadows QWidget::setWindowTitle().

Since
4.2

Sets the title of the message box to title. On Mac OS X, the window title is ignored (as required by the Mac OS X Guidelines).

Definition at line 2662 of file qmessagebox.cpp.

Referenced by aboutQt().

2663 {
2664  // Message boxes on the mac do not have a title
2665 #ifndef Q_WS_MAC
2666  QDialog::setWindowTitle(title);
2667 #else
2668  Q_UNUSED(title);
2669 #endif
2670 }
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ showEvent()

void QMessageBox::showEvent ( QShowEvent event)
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1543 of file qmessagebox.cpp.

1544 {
1545  Q_D(QMessageBox);
1546  if (d->autoAddOkButton) {
1547  addButton(Ok);
1548 #if defined(Q_WS_WINCE)
1549  d->hideSpecial();
1550 #endif
1551  }
1552  if (d->detailsButton)
1553  addButton(d->detailsButton, QMessageBox::ActionRole);
1554  d->detectEscapeButton();
1555  d->updateSize();
1556 
1557 #ifndef QT_NO_ACCESSIBILITY
1559 #endif
1560 #ifdef Q_WS_WIN
1561  HMENU systemMenu = GetSystemMenu((HWND)winId(), FALSE);
1562  if (!d->detectedEscapeButton) {
1563  EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
1564  }
1565  else {
1566  EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
1567  }
1568 #endif
1569  QDialog::showEvent(e);
1570 }
double d
Definition: qnumeric_p.h:62
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qdialog.cpp:838
#define Q_D(Class)
Definition: qglobal.h:2482
void addButton(QAbstractButton *button, ButtonRole role)
Adds the given button to the message box with the specified role.
#define FALSE
Synonym for false.
Definition: qglobal.h:1019
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557

◆ sizeHint()

QSize QMessageBox::sizeHint ( ) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QDialog.

Definition at line 1905 of file qmessagebox.cpp.

1906 {
1907  // ### Qt 5: remove
1908  return QDialog::sizeHint();
1909 }
QSize sizeHint() const
Reimplemented Function
Definition: qdialog.cpp:1160

◆ standardButton()

QMessageBox::StandardButton QMessageBox::standardButton ( QAbstractButton button) const

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

Since
4.2
See also
button(), standardButtons()

Definition at line 947 of file qmessagebox.cpp.

Referenced by showNewMessageBox().

948 {
949  Q_D(const QMessageBox);
950  return (QMessageBox::StandardButton)d->buttonBox->standardButton(button);
951 }
double d
Definition: qnumeric_p.h:62
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition: qmessagebox.h:59
#define Q_D(Class)
Definition: qglobal.h:2482
StandardButton
These enums describe flags for standard buttons.
Definition: qmessagebox.h:100

◆ standardButtons()

StandardButtons QMessageBox::standardButtons ( ) const

Referenced by setStandardButtons().

◆ standardIcon()

QPixmap QMessageBox::standardIcon ( Icon  icon)
static

Returns the pixmap used for a standard icon.

This allows the pixmaps to be used in more complex message boxes. icon specifies the required icon, e.g. QMessageBox::Question, QMessageBox::Information, QMessageBox::Warning or QMessageBox::Critical.

Call QStyle::standardIcon() with QStyle::SP_MessageBoxInformation etc. instead.

Definition at line 2844 of file qmessagebox.cpp.

Referenced by QErrorMessage::QErrorMessage(), and setWindowModality().

2845 {
2847 }
static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb)
Icon icon() const

◆ text()

QString QMessageBox::text ( ) const

◆ textFormat()

Qt::TextFormat QMessageBox::textFormat ( ) const

Referenced by setIconPixmap().

◆ warning() [1/4]

QMessageBox::StandardButton QMessageBox::warning ( QWidget parent,
const QString title,
const QString text,
StandardButtons  buttons = Ok,
StandardButton  defaultButton = NoButton 
)
static

Opens a warning message box with the given title and text in front of the specified parent widget.

Since
4.2

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 Default and Escape Keys {escape button} is returned.

The message box is an application modal dialog box.

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(), information(), critical()

Definition at line 1710 of file qmessagebox.cpp.

Referenced by QFileDialogPrivate::_q_deleteCurrent(), QFileDialogPrivate::_q_goToDirectory(), QPrintDialogPrivate::_q_okClicked(), QFileDialog::accept(), QUnixPrintWidgetPrivate::checkFields(), and QPrintDialogPrivate::openWindowsPrintDialogModally().

1713 {
1714  return showNewMessageBox(parent, Warning, title, text, buttons, defaultButton);
1715 }
QList< QAbstractButton * > buttons() const
Returns a list of all the buttons that have been added to the message box.
static QMessageBox::StandardButton showNewMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QPushButton * defaultButton() const
Returns the button that should be the message box&#39;s default button.

◆ warning() [2/4]

int QMessageBox::warning ( QWidget parent,
const QString title,
const QString text,
int  button0,
int  button1,
int  button2 = 0 
)
static

Opens a warning message box with the given title and text.

The dialog may have up to three buttons. Each of the button parameters, button0, button1 and button2 may be set to one of the following values:

If you don't want all three buttons, set the last button, or last two buttons to QMessageBox::NoButton.

One button can be OR-ed with QMessageBox::Default, and one button can be OR-ed with QMessageBox::Escape.

Returns the identity (QMessageBox::Ok or QMessageBox::No or ...) of the button that was clicked.

The message box is an application modal dialog box.

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
information(), question(), critical()

Definition at line 2331 of file qmessagebox.cpp.

2333 {
2334  return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text,
2335  button0, button1, button2);
2336 }
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)

◆ warning() [3/4]

int QMessageBox::warning ( QWidget parent,
const QString title,
const QString text,
const QString button0Text,
const QString button1Text = QString(),
const QString button2Text = QString(),
int  defaultButtonNumber = 0,
int  escapeButtonNumber = -1 
)
static

Displays a warning message box with the given title and text, as well as one, two, or three buttons.

button0Text is the text of the first button, and is optional. If button0Text is not supplied, "OK" (translated) will be used. button1Text is the text of the second button, and is optional, and button2Text is the text of the third button, and is optional. defaultButtonNumber (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). escapeButtonNumber is the index of the Escape button; pressing Escape is the same as clicking this button. It defaults to -1; supply 0, 1, or 2 to make pressing Escape equivalent to clicking the relevant button.

The message box is an application modal dialog box.

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
information(), question(), critical()

Definition at line 2370 of file qmessagebox.cpp.

2374 {
2375  return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text,
2376  button0Text, button1Text, button2Text,
2377  defaultButtonNumber, escapeButtonNumber);
2378 }
static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, int button0, int button1, int button2)

◆ warning() [4/4]

int QMessageBox::warning ( QWidget parent,
const QString title,
const QString text,
StandardButton  button0,
StandardButton  button1 
)
inlinestatic

Definition at line 257 of file qmessagebox.h.

260  { return warning(parent, title, text, StandardButtons(button0), button1); }
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens a warning message box with the given title and text in front of the specified parent widget...

Properties

◆ detailedText

QString QMessageBox::detailedText
private

the text to be displayed in the details area.

Since
4.2

The text will be interpreted as a plain text.

By default, this property contains an empty string.

See also
QMessageBox::text, QMessageBox::informativeText

Definition at line 71 of file qmessagebox.h.

◆ icon

QMessageBox::Icon QMessageBox::icon
private

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

Definition at line 66 of file qmessagebox.h.

◆ iconPixmap

QPixmap QMessageBox::iconPixmap
private

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

Definition at line 67 of file qmessagebox.h.

◆ informativeText

QString QMessageBox::informativeText
private

the informative text that provides a fuller description for the message

Since
4.2

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, QMessageBox::detailedText

Definition at line 73 of file qmessagebox.h.

◆ standardButtons

QMessageBox::StandardButtons QMessageBox::standardButtons
private

collection of standard buttons in the message box

Since
4.2

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

By default, this property contains no standard buttons.

See also
addButton()

Definition at line 69 of file qmessagebox.h.

◆ text

QString QMessageBox::text
private

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, QMessageBox::detailedText

Definition at line 64 of file qmessagebox.h.

Referenced by about().

◆ textFormat

Qt::TextFormat QMessageBox::textFormat
private

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()

Definition at line 68 of file qmessagebox.h.


The documentation for this class was generated from the following files: