Qt error message box

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

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>

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…
 
QPushButton *  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. More…
 
QPushButton *  addButton (StandardButton button)
  Adds a standard button to the message box if it is valid to do so, and returns the push button. More…
 
QAbstractButton *  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. 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…
 
QAbstractButton *  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. More…
 
QPushButton *  defaultButton () const
  Returns the button that should be the message box’s default button. More…
 
QString  detailedText () const
 
QAbstractButton *  escapeButton () 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
QWidget *  extension () 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
 
QWidget *  childAt (int x, int y) const
  Returns the visible child widget at the position ({x}, {y}) in the widget’s coordinate system. More…
 
QWidget *  childAt (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
 
QWidget *  focusProxy () const
  Returns the focus proxy, or 0 if there is no focus proxy. More…
 
QWidget *  focusWidget () const
  Returns the last child of this widget that setFocus had been called on. More…
 
const QFont &  font () 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 QRect &  geometry () 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…
 
QGraphicsEffect *  graphicsEffect () const
  The graphicsEffect function returns a pointer to the widget’s graphics effect. More…
 
QGraphicsProxyWidget *  graphicsProxyWidget () 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…
 
QInputContext *  inputContext ()
  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
 
QLayout *  layout () 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 &)
 
QWidget *  nativeParentWidget () const
  Returns the native parent for this widget, i. More…
 
QWidget *  nextInFocusChain () 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)
 
QPaintEngine *  paintEngine () const
  Returns the widget’s paint engine. More…
 
const QPalette &  palette () const
 
QWidget *  parentWidget () const
  Returns the parent of this widget, or 0 if it does not have any parent widget. More…
 
QPoint  pos () const
 
QWidget *  previousInFocusChain () 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
 
QStyle *  style () 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
 
QWidget *  topLevelWidget () 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
 
QWidget *  window () 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…
 
QWindowSurface *  windowSurface () 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 QX11Info &  x11Info () 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 QObjectList &  children () 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< QByteArray >  dynamicPropertyNames () 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 QMetaObject *  metaObject () 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
 
QObject *  parent () 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…
 
QThread *  thread () const
  Returns the thread in which the object lives. More…
 
QObjectUserData *  userData (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 QWidget *  find (WId)
  Returns a pointer to the widget with window identifer/handle id. More…
 
static QWidget *  keyboardGrabber ()
  Returns the widget that is currently grabbing the keyboard input. More…
 
static QWidget *  mouseGrabber ()
  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 QWSDisplay *  qwsDisplay ()
 

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…
 
QObject *  sender () 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< QObjectData >  d_ptr
 
- Protected Variables inherited from QPaintDevice
ushort  painters
 
- Static Protected Variables inherited from QObject
static const QMetaObject  staticQtMetaObject
 
- Related Functions inherited from QWidget
  QWidgetList
 
  WId
  Platform dependent window identifier. More…
 
- Related Functions inherited from QObject
qFindChildqFindChildren (const QObject *obj, const QString &name)()
 
QList< T >  qFindChildrenqFindChildren (const QObject *obj, const QString &name)()
 
QList< T >  qFindChildrenqFindChildren (const QObject *obj, const QRegExp &regExp)()
 
T *  qobject_cast (QObject *object)
 
  QObjectList
 
void *  qt_find_obj_child (QObject *parent, const char *type, const QString &name)
  Returns a pointer to the object named name that inherits type and with a given parent. More…
 
- Related Functions inherited from QPaintDevice
const Q_GUI_EXPORT QX11Info *  qt_x11Info (const QPaintDevice *pd)
  Returns the QX11Info structure for the pd paint device. More…
 

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.

msgBox.setText(«The document has been modified.»);

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.

msgBox.setText(«The document has been modified.»);

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

break;

break;

break;

default:

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.

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,

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.

◆ Button

◆ 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:

  • YesAll Use YesToAll instead.
  • NoAll Use NoToAll instead.
  • Default Use the defaultButton argument of information(), warning(), etc. instead, or call setDefaultButton().
  • Escape Call setEscapeButton() instead.
  • FlagMask
  • ButtonMask
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 

103  Ok = 0x00000400,

104  Save = 0x00000800,

106  Open = 0x00002000,

107  Yes = 0x00004000,

109  No = 0x00010000,

111  Abort = 0x00040000,

112  Retry = 0x00080000,

114  Close = 0x00200000,

117  Help = 0x01000000,

118  Apply = 0x02000000,

119  Reset = 0x04000000,

121 

124 

127 

128  Default = 0x00000100,

129  Escape = 0x00000200,

130  FlagMask = 0x00000300,

132  };

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 {

780  d->init();

781 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

QDialog(QWidget *parent=0, Qt::WindowFlags f=0)

Constructs a dialog with parent parent.

◆ QMessageBox() [2/3]

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 {

805  d->init(title, text);

809 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

QList< QAbstractButton * > buttons() const

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

QDialog(QWidget *parent=0, Qt::WindowFlags f=0)

Constructs a dialog with parent parent.

void setStandardButtons(StandardButtons buttons)

◆ ~QMessageBox()

QMessageBox::~QMessageBox ( )

◆ QMessageBox() [3/3]

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

The icon must be one of the following:

  • QMessageBox::NoIcon
  • QMessageBox::Question
  • QMessageBox::Information
  • QMessageBox::Warning
  • QMessageBox::Critical

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

  • QMessageBox::NoButton
  • QMessageBox::Ok
  • QMessageBox::Cancel
  • QMessageBox::Yes
  • QMessageBox::No
  • QMessageBox::Abort
  • QMessageBox::Retry
  • QMessageBox::Ignore
  • QMessageBox::YesAll
  • QMessageBox::NoAll

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

«Hardware failure.nnDisk error detectednDo you want to stop?»,

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.

2098 {

2100  d->init(title, text);

2102  d->addOldButtons(button0, button1, button2);

2103 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

QDialog(QWidget *parent=0, Qt::WindowFlags f=0)

Constructs a dialog with parent parent.

◆ about()

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

1777 

1778  if (oldMsgBox && oldMsgBox->text() == text) {

1779  oldMsgBox->show();

1780  oldMsgBox->raise();

1782  return;

1783  }

1784 #endif

1785 

1787 #ifdef Q_WS_MAC

1789 #endif

1790  );

1795 

1796 

1797 #ifdef Q_WS_MAC

1798  oldMsgBox = msgBox;

1799 #if 0

1800 

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 }

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…

The QPointer class is a template class that provides guarded pointers to QObject. …

QString text

the message box text to be displayed.

void setIconPixmap(const QPixmap &pixmap)

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.

int exec()

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

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.

The QSize class defines the size of a two-dimensional object using integer point precision.

The QIcon class provides scalable icons in different modes and states.

◆ aboutQt()

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

1830 

1831  if (oldMsgBox) {

1832  oldMsgBox->show();

1833  oldMsgBox->raise();

1835  return;

1836  }

1837 #endif

1838 

1839  QString translatedTextAboutQtCaption;

1841  «<h3>About Qt</h3>»

1842  «<p>This program uses Qt version %1.</p>»

1844  QString translatedTextAboutQtText;

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

1877  msgBox->setText(translatedTextAboutQtCaption);

1879 

1881  if (!pm.isNull())

1883 #if defined(Q_WS_WINCE)

1885 #endif

1886 

1887 

1888 #ifdef Q_WS_MAC

1889  oldMsgBox = msgBox;

1890 #if 0

1891 

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…

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.

The QPointer class is a template class that provides guarded pointers to QObject. …

void setIconPixmap(const QPixmap &pixmap)

void addButton(QAbstractButton *button, ButtonRole role)

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

bool isEmpty() const

Returns true if the string has no characters; otherwise returns false.

void setText(const QString &text)

#define QT_VERSION_STR

This macro expands to a string that specifies Qt's version number (for example, «4.

void setInformativeText(const QString &text)

QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(‘ ‘)) const Q_REQUIRED_RESULT

int exec()

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

void setDefaultButton(QPushButton *button)

Sets the message box's default button to button.

The QPixmap class is an off-screen image representation that can be used as a paint device…

void setWindowTitle(const QString &title)

This function shadows QWidget::setWindowTitle().

◆ addButton() [1/3]

◆ addButton() [2/3]

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 {

855  d->updateSize();

856  return pushButton;

857 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

The QPushButton widget provides a command button.

void addButton(QAbstractButton *button, ButtonRole role)

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

◆ addButton() [3/3]

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 {

875  if (pushButton)

876  d->autoAddOkButton = false;

877  return pushButton;

878 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

The QPushButton widget provides a command button.

QAbstractButton * button(StandardButton which) const

Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn't exi…

StandardButton

These enums describe flags for standard buttons.

◆ button()

◆ buttonClicked

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

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 {

1538 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

ButtonRole

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

◆ buttons()

◆ 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 {

2487 

2489  return abstractButton->text();

2490  } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {

2491 

2493  }

2495 }

The QAbstractButton class is the abstract base class of button widgets, providing functionality commo…

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

static QString tr(const char *sourceText, const char *comment=0, int n=-1)

The QString class provides a Unicode character string.

QAbstractButton * button(StandardButton which) const

Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn't exi…

◆ changeEvent()

void QMessageBox::changeEvent ( QEvent *  event )
protectedvirtual

Reimplemented Function

Reimplemented from QWidget.

Definition at line 1375 of file qmessagebox.cpp.

1376 {

1378  switch (ev->type()) {

1380  {

1384  d->label->setTextInteractionFlags(flags);

1386  if (d->informativeLabel)

1387  d->informativeLabel->setTextInteractionFlags(flags);

1388 

1389  }

1392 #ifdef Q_WS_MAC

1393  {

1396  d->label->setFont(f);

1397  }

1398 #endif

1399  default:

1400  break;

1401  }

1403 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

void setBold(bool)

If enable is true sets the font's weight to QFont::Bold ; otherwise sets the weight to QFont::Normal…

const char * styleHint(const QFontDef &request)

The QFont class specifies a font used for drawing text.

◆ clickedButton()

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

Since
4.2

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

Example:

messageBox.exec();

if (messageBox.clickedButton() == disconnectButton) {

}

See also
standardButton(), button()

Definition at line 1096 of file qmessagebox.cpp.

Referenced by showNewMessageBox().

1097 {

1099  return d->clickedButton;

1100 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

◆ closeEvent()

void QMessageBox::closeEvent ( QCloseEvent *  event )
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1360 of file qmessagebox.cpp.

1361 {

1363  if (!d->detectedEscapeButton) {

1364  e->ignore();

1365  return;

1366  }

1368  d->clickedButton = d->detectedEscapeButton;

1369  setResult(d->execReturnCode(d->detectedEscapeButton));

1370 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

void closeEvent(QCloseEvent *)

Reimplemented Function

void setResult(int r)

Sets the modal dialog's result code to i.

◆ critical() [1/4]

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 {

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'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:

  • QMessageBox::NoButton
  • QMessageBox::Ok
  • QMessageBox::Cancel
  • QMessageBox::Yes
  • QMessageBox::No
  • QMessageBox::Abort
  • QMessageBox::Retry
  • QMessageBox::Ignore
  • QMessageBox::YesAll
  • QMessageBox::NoAll

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 {

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]

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 {

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]

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

◆ detailedText()

QString QMessageBox::detailedText ( ) const

◆ escapeButton()

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 {

996  return d->escapeButton;

997 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

◆ event()

bool QMessageBox::event ( QEvent *  e )
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1315 of file qmessagebox.cpp.

1316 {

1318  switch (e->type()) {

1320  d_func()->updateSize();

1321  break;

1323  d_func()->retranslateStrings();

1324  break;

1325 #ifdef Q_WS_WINCE

1333  for (int i=0; i<list.size(); ++i) {

1335  if (pb->text() == bName) {

1339  }

1340  }

1341  }

1342 #endif

1343  default:

1344  break;

1345  }

1347 }

The QPushButton widget provides a command button.

The QString class provides a Unicode character string.

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.

int result() const

In general returns the modal dialog's result code, Accepted or Rejected.

int size() const

Returns the number of items in the list.

bool event(QEvent *e)

Reimplemented Function

void click()

Performs a click.

Type type() const

Returns the event type.

The QList class is a template class that provides lists.

◆ exec

int QMessageBox::exec ( )
slot

◆ icon()

Icon QMessageBox::icon ( ) const

◆ iconPixmap()

QPixmap QMessageBox::iconPixmap ( ) const

◆ information() [1/4]

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 {

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'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:

  • QMessageBox::NoButton
  • QMessageBox::Ok
  • QMessageBox::Cancel
  • QMessageBox::Yes
  • QMessageBox::No
  • QMessageBox::Abort
  • QMessageBox::Retry
  • QMessageBox::Ignore
  • QMessageBox::YesAll
  • QMessageBox::NoAll

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 {

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]

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 {

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]

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

◆ keyPressEvent()

void QMessageBox::keyPressEvent ( QKeyEvent *  event )
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1408 of file qmessagebox.cpp.

1409 {

1412 #ifdef Q_WS_MAC

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)

1429  QString textToCopy = separator;

1431  textToCopy += windowTitle() + separator;

1432  textToCopy += d->label->text() + separator;

1433 

1434  if (d->informativeLabel)

1435  textToCopy += d->informativeLabel->text() + separator;

1436 

1439  for (int i = 0; i < buttons.count(); i++) {

1440  buttonTexts += buttons[i]->text() + QLatin1String(» «);

1441  }

1442  textToCopy += buttonTexts + separator;

1443 

1445  return;

1446  }

1447 #endif //QT_NO_SHORTCUT QT_NO_CLIPBOARD Q_OS_WIN

1448 

1449 #ifndef QT_NO_SHORTCUT

1452  if (key) {

1454  for (int i = 0; i < buttons.count(); ++i) {

1457  if (acc == key) {

1459  return;

1460  }

1461  }

1462  }

1463  }

1464 #endif

1466 }

The QAbstractButton class is the abstract base class of button widgets, providing functionality commo…

void keyPressEvent(QKeyEvent *)

Reimplemented Function

QString & prepend(QChar c)

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

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.

The QString class provides a Unicode character string.

void setText(const QString &, Mode mode=Clipboard)

Copies text into the clipboard as plain text.

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.

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…

The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.

The QList class is a template class that provides lists.

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 {

1500  connect(this, signal, receiver, member);

1501  d->signalToDisconnectOnClose = signal;

1502  d->receiverToDisconnectOnClose = receiver;

1503  d->memberToDisconnectOnClose = member;

1505 }

The QAbstractButton class is the abstract base class of button widgets, providing functionality commo…

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

void buttonClicked(QAbstractButton *button)

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

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…

void open()

Shows the dialog as a window modal dialog, returning immediately.

void finished(int result)

This signal is emitted when the dialog's result code has been set, either by the user or by calling d…

◆ question() [1/4]

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 {

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'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:

  • QMessageBox::NoButton
  • QMessageBox::Ok
  • QMessageBox::Cancel
  • QMessageBox::Yes
  • QMessageBox::No
  • QMessageBox::Abort
  • QMessageBox::Retry
  • QMessageBox::Ignore
  • QMessageBox::YesAll
  • QMessageBox::NoAll

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 {

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]

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 {

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]

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

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 {

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 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

◆ resizeEvent()

void QMessageBox::resizeEvent ( QResizeEvent *  event )
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1352 of file qmessagebox.cpp.

1353 {

1355 }

void resizeEvent(QResizeEvent *)

Reimplemented Function

◆ 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 {

2513  abstractButton->setText(text);

2514  } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {

2515 

2517  }

2518 }

The QAbstractButton class is the abstract base class of button widgets, providing functionality commo…

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

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't exi…

◆ setDefaultButton() [1/2]

void QMessageBox::setDefaultButton ( QPushButton *  button )

◆ setDefaultButton() [2/2]

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 {

1156 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

QAbstractButton * button(StandardButton which) const

Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn't exi…

StandardButton

These enums describe flags for standard buttons.

void setDefaultButton(QPushButton *button)

Sets the message box's default button to button.

◆ setDetailedText()

void QMessageBox::setDetailedText ( const QString &  text )

Definition at line 2541 of file qmessagebox.cpp.

2542 {

2545  delete d->detailsText;

2546  d->detailsText = 0;

2548  delete d->detailsButton;

2549  d->detailsButton = 0;

2550  return;

2551  }

2552 

2553  if (!d->detailsText) {

2556  if (grid)

2558  d->detailsText->hide();

2559  }

2560  if (!d->detailsButton)

2562  d->detailsText->setText(text);

2563 }

void removeButton(QAbstractButton *button)

Removes button from the button box without deleting it.

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

T * qobject_cast(QObject *object)

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.

The QGridLayout class lays out widgets in a grid.

void addWidget(QWidget *w)

This is an overloaded member function, provided for convenience. It differs from the above function o…

◆ setEscapeButton() [1/2]

◆ setEscapeButton() [2/2]

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 {

1032 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

QAbstractButton * button(StandardButton which) const

Returns a pointer corresponding to the standard button which, or 0 if the standard button doesn'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 {

1249  this));

1251 }

Icon

This enum has the following values:

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

void setIconPixmap(const QPixmap &pixmap)

static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb)

◆ setIconPixmap()

void QMessageBox::setIconPixmap ( const QPixmap &  pixmap )

Definition at line 1276 of file qmessagebox.cpp.

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

1277 {

1279  d->iconLabel->setPixmap(pixmap);

1280  d->updateSize();

1282 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

◆ setInformativeText()

void QMessageBox::setInformativeText ( const QString &  text )

Definition at line 2592 of file qmessagebox.cpp.

Referenced by aboutQt().

2593 {

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

2613 #ifndef Q_WS_MAC

2614  d->label->setContentsMargins(2, 0, 0, 0);

2617 #else

2619 

2621 #endif

2624 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)

2625  label->hide();

2628 #if defined(Q_OS_SYMBIAN)

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 

2644  d->textBrowser->setText(d->informativeLabel->text());

2645 #endif

2646 

2647  d->updateSize();

2648 }

static Qt::LayoutDirection layoutDirection()

void setWordWrap(bool on)

void setOpenExternalLinks(bool open)

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

void setTextInteractionFlags(Qt::TextInteractionFlags flags)

void setOpenExternalLinks(bool open)

void setObjectName(const QString &name)

bool isEmpty() const

Returns true if the string has no characters; otherwise returns false.

const char * styleHint(const QFontDef &request)

FontHash * qt_app_fonts_hash()

The QGridLayout class lays out widgets in a grid.

The QTextBrowser class provides a rich text browser with hypertext navigation.

The QLabel widget provides a text or image display.

void addWidget(QWidget *w)

This is an overloaded member function, provided for convenience. It differs from the above function o…

void setAlignment(Qt::Alignment)

Without this function, a call to e.

void removeWidget(QWidget *w)

Removes the widget widget from the layout.

◆ setStandardButtons()

void QMessageBox::setStandardButtons ( StandardButtons  buttons )

Definition at line 916 of file qmessagebox.cpp.

Referenced by QMessageBox().

917 {

919  d->buttonBox->setStandardButtons(QDialogButtonBox::StandardButtons(int(buttons)));

920 

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 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

QList< QAbstractButton * > buttons() const

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

QBool contains(const T &t) const

Returns true if the list contains an occurrence of value; otherwise returns false.

The QList class is a template class that provides lists.

◆ setText()

void QMessageBox::setText ( const QString &  text )

Definition at line 1180 of file qmessagebox.cpp.

Referenced by aboutQt().

1181 {

1183  d->label->setText(text);

1184  d->label->setWordWrap(d->label->textFormat() == Qt::RichText

1186  d->updateSize();

1187 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

Q_GUI_EXPORT bool mightBeRichText(const QString &)

Returns true if the string text is likely to be rich text; otherwise returns false.

◆ setTextFormat()

Definition at line 1303 of file qmessagebox.cpp.

1304 {

1306  d->label->setTextFormat(format);

1309  d->updateSize();

1310 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

Q_GUI_EXPORT bool mightBeRichText(const QString &)

Returns true if the string text is likely to be rich text; otherwise returns false.

◆ setVisible()

void QMessageBox::setVisible ( bool  visible )
virtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1472 of file qmessagebox.cpp.

1473 {

1476  d->hideSpecial();

1478 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

void setVisible(bool visible)

Reimplemented Function

◆ setWindowModality()

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

2696 }

QPushButton * defaultButton() const

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

void setDefaultButton(QPushButton *button)

Sets the message box'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 

2665 #ifndef Q_WS_MAC

2667 #else

2669 #endif

2670 }

#define Q_UNUSED(x)

Indicates to the compiler that the parameter with the specified name is not used in the body of a fun…

◆ showEvent()

void QMessageBox::showEvent ( QShowEvent *  event )
protectedvirtual

Reimplemented Function

Reimplemented from QDialog.

Definition at line 1543 of file qmessagebox.cpp.

1544 {

1546  if (d->autoAddOkButton) {

1548 #if defined(Q_WS_WINCE)

1549  d->hideSpecial();

1550 #endif

1551  }

1552  if (d->detailsButton)

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

1570 }

static void updateAccessibility(QObject *, int who, Event reason)

Notifies accessibility clients about a change in object's accessibility information.

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

void showEvent(QShowEvent *)

This event handler can be reimplemented in a subclass to receive widget show events which are passed …

void addButton(QAbstractButton *button, ButtonRole role)

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

#define FALSE

Synonym for false.

◆ 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 

1909 }

QSize sizeHint() const

Reimplemented Function

◆ standardButton()

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 {

951 }

The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio…

StandardButton

These enums describe flags for standard buttons.

◆ standardButtons()

StandardButtons QMessageBox::standardButtons ( ) const

◆ standardIcon()

◆ text()

QString QMessageBox::text ( ) const

◆ textFormat()

◆ warning() [1/4]

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 {

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'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:

  • QMessageBox::NoButton
  • QMessageBox::Ok
  • QMessageBox::Cancel
  • QMessageBox::Yes
  • QMessageBox::No
  • QMessageBox::Abort
  • QMessageBox::Retry
  • QMessageBox::Ignore
  • QMessageBox::YesAll
  • QMessageBox::NoAll

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 {

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]

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 {

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]

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…

◆ detailedText

◆ icon

◆ iconPixmap

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

◆ textFormat

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:

  • /src/gui/dialogs/qmessagebox.h
  • /src/gui/dialogs/qmessagebox.cpp

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

Header: #include <QMessageBox>
CMake: find_package(Qt6 COMPONENTS Widgets REQUIRED) target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
Inherits: QDialog
  • List of all members, including inherited members
  • Deprecated members

Public Types

enum ButtonRole { InvalidRole, AcceptRole, RejectRole, DestructiveRole, ActionRole, …, ResetRole }
enum Icon { NoIcon, Question, Information, Warning, Critical }
enum StandardButton { Ok, Open, Save, Cancel, Close, …, ButtonMask }
flags StandardButtons

Properties

  • detailedText : QString
  • icon : Icon
  • iconPixmap : QPixmap
  • informativeText : QString
  • standardButtons : StandardButtons
  • text : QString
  • textFormat : Qt::TextFormat
  • textInteractionFlags : Qt::TextInteractionFlags

Public Functions

Public Slots

virtual int exec() override

Signals

Static Public Members

void about(QWidget *parent, const QString &title, const QString &text)
void aboutQt(QWidget *parent, const QString &title= QString())
QMessageBox::StandardButton critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtonsbuttons= Ok, QMessageBox::StandardButtondefaultButton= NoButton)
QMessageBox::StandardButton information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtonsbuttons= Ok, QMessageBox::StandardButtondefaultButton= NoButton)
QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtonsbuttons= StandardButtons(Yes | No), QMessageBox::StandardButtondefaultButton= NoButton)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtonsbuttons= Ok, QMessageBox::StandardButtondefaultButton= NoButton)

Reimplemented Protected Functions

Detailed Description

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.

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?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();

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

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

switch (ret) {
  case QMessageBox::Save:
      
      break;
  case QMessageBox::Discard:
      
      break;
  case QMessageBox::Cancel:
      
      break;
  default:
      
      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.

Clicking the Show Details… button displays the detailed text.

Rich Text and the Text Format Property

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

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

Severity Levels and the Icon and Pixmap Properties

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

Question For asking a question during normal operations.

Information For reporting information about normal operations.

Warning For reporting non-critical errors.

Critical For reporting critical errors.

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, useeither 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. TheMicrosoft Windows User Interface Guidelinesrecommend 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?"),
                               QMessageBox::Save | QMessageBox::Discard
                               | QMessageBox::Cancel,
                               QMessageBox::Save);

The Standard Dialogs example shows how to use QMessageBox and the other built-in Qt dialogs.


© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.2/qmessagebox.html


Qt

6.2

  • *QMenuBar::addAction(const &text, const *receiver, const char *member)

    This an overloaded function.

  • QMessageAuthenticationCode Class

    The QMessageAuthenticationCode class provides way to generate hash-based codes.

  • Advanced Usage

    If the standard buttons are not flexible enough for your message box, can use addButton() overload that takes text ButtonRole custom The default button

  • QMessageBox::QMessageBox( *parent = nullptr)

    Constructs a message box with no text and buttons.

Modal dialog with a short message, an icon, and some buttons

Synopsis

#include <qmessagebox.h>

Inherits QDialog.

Public Members

enum Icon { NoIcon = 0, Information = 1, Warning = 2, Critical = 3, Question = 4 }
QMessageBox ( QWidget * parent = 0, const char * name = 0 )
QMessageBox ( const QString & caption, const QString & text, Icon icon, int button0, int button1, int button2, QWidget * parent = 0, const char * name = 0, bool modal = TRUE, WFlags f = WStyle_DialogBorder )
~QMessageBox ()
QString text () const
void setText ( const QString & )
Icon icon () const
void setIcon ( Icon )
const QPixmap * iconPixmap () const
void setIconPixmap ( const QPixmap & )
QString buttonText ( int button ) const
void setButtonText ( int button, const QString & text )
virtual void adjustSize ()
TextFormat textFormat () const
void setTextFormat ( TextFormat )

Static Public Members

int information ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1 = 0, int button2 = 0 )
int information ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )
int question ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1 = 0, int button2 = 0 )
int question ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )
int warning ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 )
int warning ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )
int critical ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 )
int critical ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 )
void about ( QWidget * parent, const QString & caption, const QString & text )
void aboutQt ( QWidget * parent, const QString & caption = QString::null )
int message ( const QString & caption, const QString & text, const QString & buttonText = QString::null, QWidget * parent = 0, const char * = 0 )  (obsolete)
bool query ( const QString & caption, const QString & text, const QString & yesButtonText = QString::null, const QString & noButtonText = QString::null, QWidget * parent = 0, const char * = 0 )  (obsolete)
QPixmap standardIcon ( Icon icon, GUIStyle style )  (obsolete)
QPixmap standardIcon ( Icon icon )

Properties

Icon icon — the message box’s icon
QPixmap iconPixmap — the current icon
QString text — the message box text to be displayed
TextFormat textFormat — the format of the text displayed by the message box

Description

The QMessageBox class provides a modal dialog with a short message, an icon, and some buttons.

Message boxes are used to provide informative messages and to ask simple questions.

QMessageBox provides a range of different messages, arranged roughly along two axes: severity and complexity.

Severity is <center>.nf </center>

The message box has a different icon for each of the severity levels.

Complexity is one button (OK) for simple messages, or two or even three buttons for questions.

There are static functions for the most common cases.

Examples:

If a program is unable to find a supporting file, but can do perfectly well without it:

    QMessageBox::information( this, "Application name",
    "Unable to find the user preferences file.n"
    "The factory default will be used instead." );

question() is useful for simple yes/no questions:

    if ( QFile::exists( filename ) &&
        QMessageBox::question(
            this,
            tr("Overwrite File? -- Application Name"),
            tr("A file called %1 already exists."
                "Do you want to overwrite it?")
                .arg( filename ),
            tr("&Yes"), tr("&No"),
            QString::null, 0, 1 ) )
        return false;

warning() can be used to tell the user about unusual errors, or errors which can’t be easily fixed:

    switch( QMessageBox::warning( this, "Application name",
        "Could not connect to the <mumble> server.n"
        "This program can't function correctly "
        "without the server.nn",
        "Retry",
        "Quit", 0, 0, 1 ) ) {
    case 0: // The user clicked the Retry again button or pressed Enter
        // try again
        break;
    case 1: // The user clicked the Quit or pressed Escape
        // exit
        break;
    }

The text part of all message box messages can be either rich text or plain text. If you specify a rich text formatted string, it will be rendered using the default stylesheet. See QStyleSheet::defaultSheet() for details. With certain strings that contain XML meta characters, the auto-rich text detection may fail, interpreting plain text incorrectly as rich text. In these rare cases, use QStyleSheet::convertFromPlainText() to convert your plain text string to a visually equivalent rich text string or set the text format explicitly with setTextFormat().

Note that the Microsoft Windows User Interface Guidelines recommend using the application name as the window’s caption.

Below are more examples of how to use the static member functions. After these examples you will find an overview of the non-static member functions.

Exiting a program is part of its normal operation. If there is unsaved data the user probably should be asked if they want to save the data. For example:

    switch( QMessageBox::information( this, "Application name here",
        "The document contains unsaved changesn"
        "Do you want to save the changes before exiting?",
        "&Save", "&Discard", "Cancel",
        0,      // Enter == button 0
        2 ) ) { // Escape == button 2
    case 0: // Save clicked or Alt+S pressed or Enter pressed.
        // save
        break;
    case 1: // Discard clicked or Alt+D pressed
        // don't save but exit
        break;
    case 2: // Cancel clicked or Escape pressed
        // don't exit
        break;
    }

The Escape button cancels the entire exit operation, and pressing Enter causes the changes to be saved before the exit occurs.

Disk full errors are unusual and they certainly can be hard to correct. This example uses predefined buttons instead of hard-coded button texts:

    switch( QMessageBox::warning( this, "Application name here",
        "Could not save the user preferences,n"
        "because the disk is full. You can deleten"
        "some files and press Retry, or you cann"
        "abort the Save Preferences operation.",
        QMessageBox::Retry | QMessageBox::Default,
        QMessageBox::Abort | QMessageBox::Escape )) {
    case QMessageBox::Retry: // Retry clicked or Enter pressed
        // try again
        break;
    case QMessageBox::Abort: // Abort clicked or Escape pressed
        // abort
        break;
    }

The critical() function should be reserved for critical errors. In this example errorDetails is a QString or const char*, and QString is used to concatenate several strings:

    QMessageBox::critical( 0, "Application name here",
        QString("An internal error occurred. Please ") +
        "call technical support at 1234-56789 and reportn"+
        "these numbers:nn" + errorDetails +
        "nnApplication will now exit." );

In this example an OK button is displayed.

QMessageBox provides a very simple About box which displays an appropriate icon and the string you provide:

    QMessageBox::about( this, "About <Application>",
        "<Application> is a <one-paragraph blurb>nn"
        "Copyright 1991-2003 Such-and-such. "
        "<License words here.>nn"
        "For technical support, call 1234-56789 or seen"
        "http://www.such-and-such.com/Application/n" );

See about() for more information.

If you want your users to know that the application is built using Qt (so they know that you use high quality tools) you might like to add an «About Qt» menu option under the Help menu to invoke aboutQt().

If none of the standard message boxes is suitable, you can create a QMessageBox from scratch and use custom button texts:

    QMessageBox mb( "Application name here",
        "Saving the file will overwrite the original file on the disk.n"
        "Do you really want to save?",
        QMessageBox::Information,
        QMessageBox::Yes | QMessageBox::Default,
        QMessageBox::No,
        QMessageBox::Cancel | QMessageBox::Escape );
    mb.setButtonText( QMessageBox::Yes, "Save" );
    mb.setButtonText( QMessageBox::No, "Discard" );
    switch( mb.exec() ) {
    case QMessageBox::Yes:
        // save and exit
        break;
    case QMessageBox::No:
        // exit without saving
        break;
    case QMessageBox::Cancel:
        // don't save and don't exit
        break;
    }

QMessageBox defines two enum types: Icon and an unnamed button type. Icon defines the Question, Information, Warning, and Critical icons for each GUI style. It is used by the constructor and by the static member functions question(), information(), warning() and critical(). A function called standardIcon() gives you access to the various icons.

The button types are:

Ok — the default for single-button message boxes

Cancel — note that this is not automatically Escape

Yes

No

Abort

Retry

Ignore

YesAll

NoAll

Button types can be combined with two modifiers by using OR, ‘|’:

Default — makes pressing Enter equivalent to clicking this button. Normally used with Ok, Yes or similar.

Escape — makes pressing Escape equivalent to clicking this button. Normally used with Abort, Cancel or similar.

The text(), icon() and iconPixmap() functions provide access to the current text and pixmap of the message box. The setText(), setIcon() and setIconPixmap() let you change it. The difference between setIcon() and setIconPixmap() is that the former accepts a QMessageBox::Icon and can be used to set standard icons, whereas the latter accepts a QPixmap and can be used to set custom icons.

setButtonText() and buttonText() provide access to the buttons.

QMessageBox has no signals or slots.

[Image Omitted]

[Image Omitted]

See also QDialog, Isys on error messages, GUI Design Handbook: Message Box, and Dialog Classes.

Member Type Documentation

QMessageBox::Icon

This enum has the following values:

QMessageBox::NoIcon — the message box does not have any icon.

QMessageBox::Question — an icon indicating that the message is asking a question.

QMessageBox::Information — an icon indicating that the message is nothing out of the ordinary.

QMessageBox::Warning — an icon indicating that the message is a warning, but can be dealt with.

QMessageBox::Critical — an icon indicating that the message represents a critical problem.

Member Function Documentation

QMessageBox::QMessageBox ( QWidget * parent = 0, const char * name = 0 )

Constructs a message box with no text and a button with the label» OK».

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

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

QMessageBox::QMessageBox ( const QString & caption, const QString & text, Icon icon, int button0, int button1, int button2, QWidget * parent = 0, const char * name = 0, bool modal = TRUE, WFlags f = WStyle_DialogBorder )

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

The icon must be one of the following:

QMessageBox::NoIcon

QMessageBox::Question

QMessageBox::Information

QMessageBox::Warning

QMessageBox::Critical

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

QMessageBox::NoButton

QMessageBox::Ok

QMessageBox::Cancel

QMessageBox::Yes

QMessageBox::No

QMessageBox::Abort

QMessageBox::Retry

QMessageBox::Ignore

QMessageBox::YesAll

QMessageBox::NoAll

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 Escape is pressed).

Example:

    QMessageBox mb( "Application Name",
        "Hardware failure.nnDisk error detectednDo you want to stop?",
        QMessageBox::Question,
        QMessageBox::Yes | QMessageBox::Default,
        QMessageBox::No  | QMessageBox::Escape,
        QMessageBox::NoButton );
    if ( mb.exec() == QMessageBox::No )
        // try again

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

If modal is TRUE the message box is modal; otherwise it is modeless.

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

See also caption, text, and icon.

QMessageBox::~QMessageBox ()

Destroys the message box.

void QMessageBox::about ( QWidget * parent, const QString & caption, const QString & text ) [static]

Displays a simple about box with caption caption and text text. The about box’s parent is parent.

about() looks for a suitable icon in four locations: <ol type=1>

It prefers parent->icon() if that exists.

If not, it tries the top-level widget containing parent.

If that fails, it tries the main widget.

As a last resort it uses the Information icon.

The about box has a single button labelled «OK».

See also QWidget::icon and QApplication::mainWidget().

Examples:

void QMessageBox::aboutQt ( QWidget * parent, const QString & caption = QString::null ) [static]

Displays a simple message box about Qt, with caption caption 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. See the examples/menu/menu.cpp example.

QApplication provides this functionality as a slot.

See also QApplication::aboutQt().

Examples:

void QMessageBox::adjustSize () [virtual]

Adjusts the size of the message box to fit the contents just before QDialog::exec() or QDialog::show() is called.

This function will not be called if the message box has been explicitly resized before showing it.

Reimplemented from QWidget.

QString QMessageBox::buttonText ( int button ) const

Returns the text of the message box button button, or QString::null if the message box does not contain the button.

See also setButtonText().

int QMessageBox::critical ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 ) [static]

Opens a critical message box with the caption caption and the text 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:

QMessageBox::NoButton

QMessageBox::Ok

QMessageBox::Cancel

QMessageBox::Yes

QMessageBox::No

QMessageBox::Abort

QMessageBox::Retry

QMessageBox::Ignore

QMessageBox::YesAll

QMessageBox::NoAll

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.

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

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

Examples:

int QMessageBox::critical ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Displays a critical error message box with a caption, a text, and 1, 2 or 3 buttons. Returns the number of the button that was clicked (0, 1 or 2).

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.

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

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

Icon QMessageBox::icon () const

Returns the message box’s icon. See the «icon» property for details.

const QPixmap * QMessageBox::iconPixmap () const

Returns the current icon. See the «iconPixmap» property for details.

int QMessageBox::information ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1 = 0, int button2 = 0 ) [static]

Opens an information message box with the caption caption and the text 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:

QMessageBox::NoButton

QMessageBox::Ok

QMessageBox::Cancel

QMessageBox::Yes

QMessageBox::No

QMessageBox::Abort

QMessageBox::Retry

QMessageBox::Ignore

QMessageBox::YesAll

QMessageBox::NoAll

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.

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

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

Examples:

int QMessageBox::information ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Displays an information message box with caption caption, text text and one, two or three buttons. Returns the index of the button that was clicked (0, 1 or 2).

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.

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

Note: If you do not specify an Escape button then if the Escape button is pressed then -1 will be returned. It is suggested that you specify an Escape button to prevent this from happening.

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

int QMessageBox::message ( const QString & caption, const QString & text, const QString & buttonText = QString::null, QWidget * parent = 0, const char * = 0 ) [static]

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Opens a modal message box directly using the specified parameters.

Please use information(), warning(), question(), or critical() instead.

Example: grapher/grapher.cpp.

bool QMessageBox::query ( const QString & caption, const QString & text, const QString & yesButtonText = QString::null, const QString & noButtonText = QString::null, QWidget * parent = 0, const char * = 0 ) [static]

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Queries the user using a modal message box with two buttons. Note that caption is not always shown, it depends on the window manager.

Please use information(), question(), warning(), or critical() instead.

int QMessageBox::question ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1 = 0, int button2 = 0 ) [static]

Opens a question message box with the caption caption and the text 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:

QMessageBox::NoButton

QMessageBox::Ok

QMessageBox::Cancel

QMessageBox::Yes

QMessageBox::No

QMessageBox::Abort

QMessageBox::Retry

QMessageBox::Ignore

QMessageBox::YesAll

QMessageBox::NoAll

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.

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

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

int QMessageBox::question ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Displays a question message box with caption caption, text text and one, two or three buttons. Returns the index of the button that was clicked (0, 1 or 2).

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.

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

Note: If you do not specify an Escape button then if the Escape button is pressed then -1 will be returned. It is suggested that you specify an Escape button to prevent this from happening.

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

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.

See also buttonText().

void QMessageBox::setIcon ( Icon )

Sets the message box’s icon. See the «icon» property for details.

void QMessageBox::setIconPixmap ( const QPixmap & )

Sets the current icon. See the «iconPixmap» property for details.

void QMessageBox::setText ( const QString & )

Sets the message box text to be displayed. See the «text» property for details.

void QMessageBox::setTextFormat ( TextFormat )

Sets the format of the text displayed by the message box. See the «textFormat» property for details.

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.

QPixmap QMessageBox::standardIcon ( Icon icon, GUIStyle style ) [static]

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

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::Information, QMessageBox::Warning or QMessageBox::Critical.

style is unused.

QString QMessageBox::text () const

Returns the message box text to be displayed. See the «text» property for details.

TextFormat QMessageBox::textFormat () const

Returns the format of the text displayed by the message box. See the «textFormat» property for details.

int QMessageBox::warning ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1, int button2 = 0 ) [static]

Opens a warning message box with the caption caption and the text 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:

QMessageBox::NoButton

QMessageBox::Ok

QMessageBox::Cancel

QMessageBox::Yes

QMessageBox::No

QMessageBox::Abort

QMessageBox::Retry

QMessageBox::Ignore

QMessageBox::YesAll

QMessageBox::NoAll

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.

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

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

Examples:

int QMessageBox::warning ( QWidget * parent, const QString & caption, const QString & text, const QString & button0Text = QString::null, const QString & button1Text = QString::null, const QString & button2Text = QString::null, int defaultButtonNumber = 0, int escapeButtonNumber = -1 ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Displays a warning message box with a caption, a text, and 1, 2 or 3 buttons. Returns the number of the button that was clicked (0, 1, or 2).

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.

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

Note: If you do not specify an Escape button then if the Escape button is pressed then -1 will be returned. It is suggested that you specify an Escape button to prevent this from happening.

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

Property Documentation

Icon icon

This property holds the message box’s icon.

The icon of the message box can be one of the following predefined icons:

QMessageBox::NoIcon

QMessageBox::Question

QMessageBox::Information

QMessageBox::Warning

QMessageBox::Critical

The actual pixmap used for displaying the icon depends on the current GUI style. You can also set a custom pixmap icon using the QMessageBox::iconPixmap property. The default icon is QMessageBox::NoIcon.

See also iconPixmap.

Set this property’s value with setIcon() and get this property’s value with icon().

QPixmap iconPixmap

This property holds the current icon.

The icon currently used by the message box. Note that it’s often hard to draw one pixmap that looks appropriate in both Motif and Windows GUI styles; you may want to draw two pixmaps.

See also icon.

Set this property’s value with setIconPixmap() and get this property’s value with iconPixmap().

QString text

This property holds the message box text to be displayed.

The text will be interpreted either as a plain text or as rich text, depending on the text format setting (QMessageBox::textFormat). The default setting is AutoText, i.e. the message box will try to auto-detect the format of the text.

The default value of this property is QString::null.

See also textFormat.

Set this property’s value with setText() and get this property’s value with text().

TextFormat textFormat

This property holds the format of the text displayed by the message box.

The current text format used by the message box. See the Qt::TextFormat enum for an explanation of the possible options.

The default format is AutoText.

See also text.

Set this property’s value with setTextFormat() and get this property’s value with textFormat().

See Also

http://doc.trolltech.com/qmessagebox.html http://www.trolltech.com/faq/tech.html

Copyright

Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the license file included in the distribution for a complete license statement.

Bugs

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you.

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qmessagebox.3qt) and the Qt version (3.3.8).

Referenced By

The man page QMessageBox.3qt(3) is an alias of qmessagebox.3qt(3).

2 February 2007 Trolltech AS

Понравилась статья? Поделить с друзьями:
  • Pyttsx3 как изменить голос
  • Pyttsx3 init error
  • Qt creator ошибка при запуске приложения 0xc000005
  • Pythonpath как изменить
  • Qt creator ошибка qmake