Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QMessageBox Class Reference

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

#include <qmessagebox.h>

+ Inheritance diagram for QMessageBox:
+ Collaboration diagram for QMessageBox:

Public Types

enum class  Option { DontUseNativeDialog = 0x00000001 }
 
enum  Icon {
  NoIcon = 0 , Information = 1 , Warning = 2 , Critical = 3 ,
  Question = 4
}
 This enum has the following values: More...
 
enum  ButtonRole {
  InvalidRole = -1 , AcceptRole , RejectRole , DestructiveRole ,
  ActionRole , HelpRole , YesRole , NoRole ,
  ResetRole , ApplyRole , NRoles
}
 
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
}
 
- 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 , PdmDevicePixelRatio , PdmDevicePixelRatioScaled
}
 

Public Slots

virtual void open ()
 
- Public Slots inherited from QDialog
virtual void open ()
 
virtual int exec ()
 Shows the dialog as a \l{QDialog::Modal Dialogs}{modal dialog}, blocking until the user closes it.
 
virtual void done (int)
 Closes the dialog and sets its result code to r.
 
virtual void accept ()
 Hides the modal dialog and sets the result code to Accepted.
 
virtual void reject ()
 Hides the modal dialog and sets the result code to Rejected.
 
- Public Slots inherited from QWidget
void setEnabled (bool)
 
void setDisabled (bool)
 Disables widget input events if disable is true; otherwise enables input events.
 
void setWindowModified (bool)
 
void setWindowTitle (const QString &)
 
void setStyleSheet (const QString &styleSheet)
 
void setFocus ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the \l{isActiveWindow()}{active window}.
 
void update ()
 Updates the widget unless updates are disabled or the widget is hidden.
 
void repaint ()
 Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden.
 
void setHidden (bool hidden)
 Convenience function, equivalent to setVisible(!hidden).
 
void show ()
 Shows the widget and its child widgets.
 
void hide ()
 Hides the widget.
 
void showMinimized ()
 Shows the widget minimized, as an icon.
 
void showMaximized ()
 Shows the widget maximized.
 
void showFullScreen ()
 Shows the widget in full-screen mode.
 
void showNormal ()
 Restores the widget after it has been maximized or minimized.
 
bool close ()
 Closes this widget.
 
void raise ()
 Raises this widget to the top of the parent widget's stack.
 
void lower ()
 Lowers the widget to the bottom of the parent widget's stack.
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 

Signals

void buttonClicked (QAbstractButton *button)
 This signal is emitted whenever a button is clicked inside the QMessageBox.
 
- Signals inherited from QDialog
void finished (int result)
 
void accepted ()
 
void rejected ()
 
- Signals inherited from QWidget
void windowTitleChanged (const QString &title)
 This signal is emitted when the window's title has changed, with the new title as an argument.
 
void windowIconChanged (const QIcon &icon)
 This signal is emitted when the window's icon has changed, with the new icon as an argument.
 
void windowIconTextChanged (const QString &iconText)
 This signal is emitted when the window's icon text has changed, with the new iconText as an argument.
 
void customContextMenuRequested (const QPoint &pos)
 This signal is emitted when the widget's \l contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget.
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QMessageBox (QWidget *parent=nullptr)
 Constructs an \l{Qt::ApplicationModal} {application modal} message box with no text and no buttons.
 
 QMessageBox (Icon icon, const QString &title, const QString &text, StandardButtons buttons=NoButton, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint)
 Constructs an \l{Qt::ApplicationModal} {application modal} message box with the given icon, title, text, and standard buttons.
 
 ~QMessageBox ()
 Destroys the message box.
 
void addButton (QAbstractButton *button, ButtonRole role)
 
QPushButtonaddButton (const QString &text, ButtonRole role)
 
QPushButtonaddButton (StandardButton button)
 
void removeButton (QAbstractButton *button)
 
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.
 
QList< QAbstractButton * > buttons () const
 
ButtonRole buttonRole (QAbstractButton *button) const
 
void setStandardButtons (StandardButtons buttons)
 
StandardButtons standardButtons () const
 
StandardButton standardButton (QAbstractButton *button) const
 
QAbstractButtonbutton (StandardButton which) const
 
QPushButtondefaultButton () const
 
void setDefaultButton (QPushButton *button)
 
void setDefaultButton (StandardButton button)
 
QAbstractButtonescapeButton () const
 
void setEscapeButton (QAbstractButton *button)
 
void setEscapeButton (StandardButton button)
 
QAbstractButtonclickedButton () const
 
QString text () const
 
void setText (const QString &text)
 
Icon icon () const
 
void setIcon (Icon)
 
QPixmap iconPixmap () const
 
void setIconPixmap (const QPixmap &pixmap)
 
Qt::TextFormat textFormat () const
 
void setTextFormat (Qt::TextFormat format)
 
void setTextInteractionFlags (Qt::TextInteractionFlags flags)
 
Qt::TextInteractionFlags textInteractionFlags () const
 
void setCheckBox (QCheckBox *cb)
 
QCheckBoxcheckBox () const
 
void setOption (Option option, bool on=true)
 
bool testOption (Option option) const
 
void setOptions (Options options)
 
Options options () const
 
QString informativeText () const
 
void setInformativeText (const QString &text)
 
void setWindowTitle (const QString &title)
 
void setWindowModality (Qt::WindowModality windowModality)
 
- Public Member Functions inherited from QDialog
 QDialog (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 Constructs a dialog with parent parent.
 
 ~QDialog ()
 Destroys the QDialog, deleting all its children.
 
int result () const
 In general returns the modal dialog's result code, Accepted or Rejected.
 
void setVisible (bool visible) override
 \reimp
 
QSize sizeHint () const override
 \reimp
 
QSize minimumSizeHint () const override
 \reimp
 
void setSizeGripEnabled (bool)
 
bool isSizeGripEnabled () const
 
void setModal (bool modal)
 
void setResult (int r)
 Sets the modal dialog's result code to i.
 
- Public Member Functions inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
 Constructs a widget which is a child of parent, with widget flags set to f.
 
 ~QWidget ()
 Destroys the widget.
 
int devType () const override
 
WId winId () const
 Returns the window system identifier of the widget.
 
void createWinId ()
 
WId internalWinId () const
 
WId effectiveWinId () const
 
QStylestyle () const
 
void setStyle (QStyle *)
 Sets the widget's GUI style to style.
 
bool isWindow () const
 Returns true if the widget is an independent window, otherwise returns false.
 
bool isModal () const
 
Qt::WindowModality windowModality () const
 
void setWindowModality (Qt::WindowModality windowModality)
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *) const
 Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false.
 
QRect frameGeometry () const
 
const QRectgeometry () const
 
QRect normalGeometry () const
 
int x () const
 
int y () const
 
QPoint pos () const
 
QSize frameSize () const
 
QSize size () const
 
int width () const
 
int height () const
 
QRect rect () const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
QSize minimumSize () const
 
QSize maximumSize () const
 
int minimumWidth () const
 
int minimumHeight () const
 
int maximumWidth () const
 
int maximumHeight () const
 
void setMinimumSize (const QSize &)
 
void setMinimumSize (int minw, int minh)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function corresponds to setMinimumSize(QSize(minw, minh)).
 
void setMaximumSize (const QSize &)
 
void setMaximumSize (int maxw, int maxh)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function corresponds to setMaximumSize(QSize(maxw, maxh)).
 
void setMinimumWidth (int minw)
 
void setMinimumHeight (int minh)
 
void setMaximumWidth (int maxw)
 
void setMaximumHeight (int maxh)
 
QSize sizeIncrement () const
 
void setSizeIncrement (const QSize &)
 
void setSizeIncrement (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.Sets the x (width) size increment to w and the y (height) size increment to h.
 
QSize baseSize () const
 
void setBaseSize (const QSize &)
 
void setBaseSize (int basew, int baseh)
 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 setBaseSize(QSize(basew, baseh)).
 
void setFixedSize (const QSize &)
 Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking.
 
void setFixedSize (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.Sets the width of the widget to w and the height to h.
 
void setFixedWidth (int w)
 Sets both the minimum and maximum width of the widget to w without changing the heights.
 
void setFixedHeight (int h)
 Sets both the minimum and maximum heights of the widget to h without changing the widths.
 
QPointF mapToGlobal (const QPointF &) const
 Translates the widget coordinate pos to global screen coordinates.
 
QPoint mapToGlobal (const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapFromGlobal (const QPointF &) const
 Translates the global screen coordinate pos to widget coordinates.
 
QPoint mapFromGlobal (const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapToParent (const QPointF &) const
 Translates the widget coordinate pos to a coordinate in the parent widget.
 
QPoint mapToParent (const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapFromParent (const QPointF &) const
 Translates the parent widget coordinate pos to widget coordinates.
 
QPoint mapFromParent (const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapTo (const QWidget *, const QPointF &) const
 Translates the widget coordinate pos to the coordinate system of parent.
 
QPoint mapTo (const QWidget *, const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QPointF mapFrom (const QWidget *, const QPointF &) const
 Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system.
 
QPoint mapFrom (const QWidget *, const QPoint &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QWidgetwindow () const
 Returns the window for this widget, i.e.
 
QWidgetnativeParentWidget () const
 
QWidgettopLevelWidget () const
 
const QPalettepalette () const
 
void setPalette (const QPalette &)
 
void setBackgroundRole (QPalette::ColorRole)
 Sets the background role of the widget to role.
 
QPalette::ColorRole backgroundRole () const
 Returns the background role of the widget.
 
void setForegroundRole (QPalette::ColorRole)
 Sets the foreground role of the widget to role.
 
QPalette::ColorRole foregroundRole () const
 Returns the foreground role.
 
const QFontfont () const
 
void setFont (const QFont &)
 
QFontMetrics fontMetrics () const
 Returns the font metrics for the widget's current font.
 
QFontInfo fontInfo () const
 Returns the font info for the widget's current font.
 
QCursor cursor () const
 
void setCursor (const QCursor &)
 
void unsetCursor ()
 
void setMouseTracking (bool enable)
 
bool hasMouseTracking () const
 
bool underMouse () const
 Returns true if the widget is under the mouse cursor; otherwise returns false.
 
void setTabletTracking (bool enable)
 
bool hasTabletTracking () const
 
void setMask (const QBitmap &)
 Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible.
 
void setMask (const QRegion &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Causes only the parts of the widget which overlap region to be visible.
 
QRegion mask () const
 Returns the mask currently set on a widget.
 
void clearMask ()
 Removes any mask set by setMask().
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Renders the widget into the painter's QPainter::device().
 
Q_INVOKABLE QPixmap grab (const QRect &rectangle=QRect(QPoint(0, 0), QSize(-1, -1)))
 
void grabGesture (Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
 Subscribes the widget to a given gesture with specific flags.
 
void ungrabGesture (Qt::GestureType type)
 Unsubscribes the widget from a given gesture type.
 
QString styleSheet () const
 
QString windowTitle () const
 
void setWindowIcon (const QIcon &icon)
 
QIcon windowIcon () const
 
void setWindowIconText (const QString &)
 
QString windowIconText () const
 
void setWindowRole (const QString &)
 Sets the window's role to role.
 
QString windowRole () const
 Returns the window's role, or an empty string.
 
void setWindowFilePath (const QString &filePath)
 
QString windowFilePath () const
 
void setWindowOpacity (qreal level)
 
qreal windowOpacity () const
 
bool isWindowModified () const
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
Qt::LayoutDirection layoutDirection () const
 
void unsetLayoutDirection ()
 
void setLocale (const QLocale &locale)
 
QLocale locale () const
 
void unsetLocale ()
 
bool isRightToLeft () const
 
bool isLeftToRight () const
 
bool isActiveWindow () const
 
void activateWindow ()
 Sets the top-level widget containing this widget to be the active window.
 
void clearFocus ()
 Takes keyboard input focus from the widget.
 
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 \l{isActiveWindow()}{active window}.
 
Qt::FocusPolicy focusPolicy () const
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
bool hasFocus () const
 
void setFocusProxy (QWidget *)
 Sets the widget's focus proxy to widget w.
 
QWidgetfocusProxy () const
 Returns the focus proxy, or \nullptr if there is no focus proxy.
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void grabMouse ()
 Grabs the mouse input.
 
void grabMouse (const QCursor &)
 
void releaseMouse ()
 Releases the mouse grab.
 
void grabKeyboard ()
 Grabs the keyboard input.
 
void releaseKeyboard ()
 Releases the keyboard grab.
 
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.
 
void releaseShortcut (int id)
 Removes the shortcut with the given id from Qt's shortcut system.
 
void setShortcutEnabled (int id, bool enable=true)
 If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled.
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
bool updatesEnabled () const
 
void setUpdatesEnabled (bool enable)
 
void update (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 version updates a rectangle (x, y, w, h) inside the widget.
 
void update (const QRect &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version updates a rectangle rect inside the widget.
 
void update (const QRegion &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a region rgn inside the widget.
 
void repaint (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 version repaints a rectangle (x, y, w, h) inside the widget.
 
void repaint (const QRect &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a rectangle rect inside the widget.
 
void repaint (const QRegion &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version repaints a region rgn inside the widget.
 
void stackUnder (QWidget *)
 Places the widget under w in the parent widget's stack.
 
void move (int x, int y)
 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 move(QPoint(x, y)).
 
void move (const QPoint &)
 
void resize (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 resize(QSize(w, h)).
 
void resize (const QSize &)
 
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)).
 
void setGeometry (const QRect &)
 
QByteArray saveGeometry () const
 
bool restoreGeometry (const QByteArray &geometry)
 
void adjustSize ()
 Adjusts the size of the widget to fit its contents.
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *) const
 Returns true if this widget would become visible if ancestor is shown; otherwise returns false.
 
bool isHidden () const
 Returns true if the widget is hidden, otherwise returns false.
 
bool isMinimized () const
 
bool isMaximized () const
 
bool isFullScreen () const
 
Qt::WindowStates windowState () const
 Returns the current window state.
 
void setWindowState (Qt::WindowStates state)
 Sets the window state to windowState.
 
void overrideWindowState (Qt::WindowStates state)
 
QSizePolicy sizePolicy () const
 
void setSizePolicy (QSizePolicy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the size policy of the widget to horizontal and vertical, with standard stretch and no height-for-width.
 
virtual int heightForWidth (int) const
 Returns the preferred height for this widget, given the width w.
 
virtual bool hasHeightForWidth () const
 
QRegion visibleRegion () const
 Returns the unobscured region where paint events can occur.
 
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.
 
void setContentsMargins (const QMargins &margins)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QMargins contentsMargins () const
 The contentsMargins function returns the widget's contents margins.
 
QRect contentsRect () const
 Returns the area inside the widget's margins.
 
QLayoutlayout () const
 Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is installed.
 
void setLayout (QLayout *)
 Sets the layout manager for this widget to layout.
 
void updateGeometry ()
 Notifies the layout system that this widget has changed and may need to change geometry.
 
void setParent (QWidget *parent)
 Sets the parent of the widget to parent, and resets the window flags.
 
void setParent (QWidget *parent, Qt::WindowFlags f)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function also takes widget flags, f as an argument.
 
void scroll (int dx, int dy)
 Scrolls the widget including its children dx pixels to the right and dy downward.
 
void scroll (int dx, int dy, const QRect &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This version only scrolls r and does not move the children of the widget.
 
QWidgetfocusWidget () const
 Returns the last child of this widget that setFocus had been called on.
 
QWidgetnextInFocusChain () const
 Returns the next widget in this widget's focus chain.
 
QWidgetpreviousInFocusChain () const
 The previousInFocusChain function returns the previous widget in this widget's focus chain.
 
bool acceptDrops () const
 
void setAcceptDrops (bool on)
 
void addAction (QAction *action)
 Appends the action action to this widget's list of actions.
 
void addActions (const QList< QAction * > &actions)
 Appends the actions actions to this widget's list of actions.
 
void insertActions (QAction *before, const QList< QAction * > &actions)
 Inserts the actions actions to this widget's list of actions, before the action before.
 
void insertAction (QAction *before, QAction *action)
 Inserts the action action to this widget's list of actions, before the action before.
 
void removeAction (QAction *action)
 Removes the action action from this widget's list of actions.
 
QList< QAction * > actions () const
 Returns the (possibly empty) list of this widget's actions.
 
QActionaddAction (const QString &text)
 
QActionaddAction (const QIcon &icon, const QString &text)
 
QActionaddAction (const QString &text, const QObject *receiver, const char *member, Qt::ConnectionType type=Qt::AutoConnection)
 
QActionaddAction (const QIcon &icon, const QString &text, const QObject *receiver, const char *member, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename... Args, typename = compatible_action_slot_args<Args...>>
QActionaddAction (const QString &text, Args &&...args)
 
template<typename... Args, typename = compatible_action_slot_args<Args...>>
QActionaddAction (const QIcon &icon, const QString &text, Args &&...args)
 
QWidgetparentWidget () const
 Returns the parent of this widget, or \nullptr if it does not have any parent widget.
 
void setWindowFlags (Qt::WindowFlags type)
 
Qt::WindowFlags windowFlags () const
 Window flags are a combination of a type (e.g.
 
void setWindowFlag (Qt::WindowType, bool on=true)
 
void overrideWindowFlags (Qt::WindowFlags type)
 Sets the window flags for the widget to flags, without telling the window system.
 
Qt::WindowType windowType () const
 Returns the window type of this widget.
 
QWidgetchildAt (int x, int y) const
 Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system.
 
QWidgetchildAt (const QPoint &p) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the visible child widget at point p in the widget's own coordinate system.
 
void setAttribute (Qt::WidgetAttribute, bool on=true)
 Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
 
bool testAttribute (Qt::WidgetAttribute) const
 Returns true if attribute attribute is set on this widget; otherwise returns false.
 
QPaintEnginepaintEngine () const override
 Returns the widget's paint engine.
 
void ensurePolished () const
 Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and palette).
 
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.
 
bool autoFillBackground () const
 
void setAutoFillBackground (bool enabled)
 
QBackingStorebackingStore () const
 
QWindowwindowHandle () const
 If this is a native widget, return the associated QWindow.
 
QScreenscreen () const
 Returns the screen the widget is on.
 
void setScreen (QScreen *)
 Sets the screen on which the widget should be shown to screen.
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery) const
 This method is only relevant for input widgets.
 
Qt::InputMethodHints inputMethodHints () const
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) 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.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
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.
 
- Public Member Functions inherited from QPaintDevice
virtual ~QPaintDevice ()
 
bool paintingActive () const
 
int width () const
 
int height () const
 
int widthMM () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
qreal devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int colorCount () const
 
int depth () const
 

Static Public Member Functions

static StandardButton information (QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
 
static StandardButton question (QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=StandardButtons(Yes|No), StandardButton defaultButton=NoButton)
 
static StandardButton warning (QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
 
static StandardButton critical (QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
 
static void about (QWidget *parent, const QString &title, const QString &text)
 Displays a simple about box with title title and text text.
 
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 \nullptr).
 
- Static Public Member Functions inherited from QWidget
static void setTabOrder (QWidget *, QWidget *)
 Puts the second widget after the first widget in the focus order.
 
static void setTabOrder (std::initializer_list< QWidget * > widgets)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
static QWidgetmouseGrabber ()
 Returns the widget that is currently grabbing the mouse input.
 
static QWidgetkeyboardGrabber ()
 Returns the widget that is currently grabbing the keyboard input.
 
static QWidgetfind (WId)
 Returns a pointer to the widget with window identifier/handle id.
 
static QWidgetcreateWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
 Creates a QWidget that makes it possible to embed window into a QWidget-based application.
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Static Public Member Functions inherited from QPaintDevice
static qreal devicePixelRatioFScale ()
 

Protected Member Functions

bool event (QEvent *e) override
 \reimp
 
void resizeEvent (QResizeEvent *event) override
 \reimp
 
void showEvent (QShowEvent *event) override
 \reimp
 
void closeEvent (QCloseEvent *event) override
 \reimp
 
void keyPressEvent (QKeyEvent *event) override
 \reimp
 
void changeEvent (QEvent *event) override
 \reimp
 
- Protected Member Functions inherited from QDialog
 QDialog (QDialogPrivate &, QWidget *parent, Qt::WindowFlags f=Qt::WindowFlags())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void contextMenuEvent (QContextMenuEvent *) override
 \reimp
 
bool eventFilter (QObject *, QEvent *) override
 \reimp
 
void adjustPosition (QWidget *)
 
- Protected Member Functions inherited from QWidget
bool event (QEvent *event) override
 This is the main event handler; it handles event event.
 
virtual void mousePressEvent (QMouseEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse release events for the widget.
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse double click events for the widget.
 
virtual void mouseMoveEvent (QMouseEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget.
 
virtual void keyReleaseEvent (QKeyEvent *event)
 This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget.
 
virtual void focusInEvent (QFocusEvent *event)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget.
 
virtual void focusOutEvent (QFocusEvent *event)
 This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget.
 
virtual void enterEvent (QEnterEvent *event)
 This event handler can be reimplemented in a subclass to receive widget enter events which are passed in the event parameter.
 
virtual void leaveEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive widget leave events which are passed in the event parameter.
 
virtual void paintEvent (QPaintEvent *event)
 This event handler can be reimplemented in a subclass to receive paint events passed in event.
 
virtual void moveEvent (QMoveEvent *event)
 This event handler can be reimplemented in a subclass to receive widget move events which are passed in the event parameter.
 
virtual void actionEvent (QActionEvent *event)
 This event handler is called with the given event whenever the widget's actions are changed.
 
virtual void hideEvent (QHideEvent *event)
 This event handler can be reimplemented in a subclass to receive widget hide events.
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, qintptr *result)
 This special event handler can be reimplemented in a subclass to receive native platform events identified by eventType which are passed in the message parameter.
 
int metric (PaintDeviceMetric) const override
 Internal implementation of the virtual QPaintDevice::metric() function.
 
void initPainter (QPainter *painter) const override
 Initializes the painter pen, background and font to the same as the given widget's.
 
QPaintDeviceredirected (QPoint *offset) const override
 
QPaintersharedPainter () const override
 
virtual void inputMethodEvent (QInputMethodEvent *)
 This event handler, for event event, can be reimplemented in a subclass to receive Input Method composition events.
 
void create (WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
 Creates a new widget window.
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 Frees up window system resources.
 
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.
 
bool focusNextChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for \uicontrol Tab, and returns true if it can find a new widget, or false if it can't.
 
bool focusPreviousChild ()
 Finds a new widget to give the keyboard focus to, as appropriate for \uicontrol Shift+Tab, and returns true if it can find a new widget, or false if it can't.
 
 QWidget (QWidgetPrivate &d, QWidget *parent, Qt::WindowFlags f)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QPaintDevice
 QPaintDevice () noexcept
 

Properties

QString text
 the message box text to be displayed.
 
Icon icon
 the message box's icon
 
QPixmap iconPixmap
 the current icon
 
Qt::TextFormat textFormat
 the format of the text displayed by the message box
 
StandardButtons standardButtons
 collection of standard buttons in the message box
 
QString informativeText
 the informative text that provides a fuller description for the message
 
Qt::TextInteractionFlags textInteractionFlags
 
Options options
 Options that affect the look and feel of the dialog.
 
- Properties inherited from QDialog
bool sizeGripEnabled
 whether the size grip is enabled
 
bool modal
 whether show() should pop up the dialog as modal or modeless
 
- Properties inherited from QWidget
bool modal
 whether the widget is a modal widget
 
Qt::WindowModality windowModality
 which windows are blocked by the modal widget
 
bool enabled
 whether the widget is enabled
 
QRect geometry
 the geometry of the widget relative to its parent and excluding the window frame
 
QRect frameGeometry
 geometry of the widget relative to its parent including any window frame
 
QRect normalGeometry
 the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget
 
int x
 the x coordinate of the widget relative to its parent including any window frame
 
int y
 the y coordinate of the widget relative to its parent and including any window frame
 
QPoint pos
 the position of the widget within its parent widget
 
QSize frameSize
 the size of the widget including any window frame
 
QSize size
 the size of the widget excluding any window frame
 
int width
 the width of the widget excluding any window frame
 
int height
 the height of the widget excluding any window frame
 
QRect rect
 the internal geometry of the widget excluding any window frame
 
QRect childrenRect
 the bounding rectangle of the widget's children
 
QRegion childrenRegion
 the combined region occupied by the widget's children
 
QSizePolicy sizePolicy
 the default layout behavior of the widget
 
QSize minimumSize
 the widget's minimum size
 
QSize maximumSize
 the widget's maximum size in pixels
 
int minimumWidth
 the widget's minimum width in pixels
 
int minimumHeight
 the widget's minimum height in pixels
 
int maximumWidth
 the widget's maximum width in pixels
 
int maximumHeight
 the widget's maximum height in pixels
 
QSize sizeIncrement
 the size increment of the widget
 
QSize baseSize
 the base size of the widget
 
QPalette palette
 the widget's palette
 
QFont font
 the font currently set for the widget
 
QCursor cursor
 the cursor shape for this widget
 
bool mouseTracking
 whether mouse tracking is enabled for the widget
 
bool tabletTracking
 whether tablet tracking is enabled for the widget
 
bool isActiveWindow
 whether this widget's window is the active window
 
Qt::FocusPolicy focusPolicy
 the way the widget accepts keyboard focus
 
bool focus
 whether this widget (or its focus proxy) has the keyboard input focus
 
Qt::ContextMenuPolicy contextMenuPolicy
 how the widget shows a context menu
 
bool updatesEnabled
 whether updates are enabled
 
bool visible
 whether the widget is visible
 
bool minimized
 whether this widget is minimized (iconified)
 
bool maximized
 whether this widget is maximized
 
bool fullScreen
 whether the widget is shown in full screen mode
 
QSize sizeHint
 the recommended size for the widget
 
QSize minimumSizeHint
 the recommended minimum size for the widget
 
bool acceptDrops
 whether drop events are enabled for this widget
 
QString windowTitle
 the window title (caption)
 
QIcon windowIcon
 the widget's icon
 
QString windowIconText
 the text to be displayed on the icon of a minimized window
 
double windowOpacity
 The level of opacity for the window.
 
bool windowModified
 whether the document shown in the window has unsaved changes
 
Qt::LayoutDirection layoutDirection
 the layout direction for this widget.
 
bool autoFillBackground
 whether the widget background is filled automatically
 
QString styleSheet
 the widget's style sheet
 
QLocale locale
 the widget's locale
 
QString windowFilePath
 the file path associated with a widget
 
Qt::InputMethodHints inputMethodHints
 What input method specific hints the widget has.
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Additional Inherited Members

- Protected Slots inherited from QWidget
void updateMicroFocus (Qt::InputMethodQuery query=Qt::ImQueryAll)
 Updates the widget's micro focus and informs input methods that the state specified by query has changed.
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Attributes inherited from QPaintDevice
ushort painters
 

Detailed Description

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

\inmodule QtWidgets

A message box displays a primary \l{QMessageBox::text}{text} to alert the user to a situation, an \l{QMessageBox::informativeText} {informative text} to further explain the situation, and an optional \l{QMessageBox::detailedText} {detailed text} to provide even more data if the user requests it.

A message box can also display an \l{QMessageBox::icon} {icon} and \l{QMessageBox::standardButtons} {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.

Definition at line 21 of file qmessagebox.h.

Member Enumeration Documentation

◆ ButtonRole

buttonrole-enum

Enumerator
InvalidRole 
AcceptRole 
RejectRole 
DestructiveRole 
ActionRole 
HelpRole 
YesRole 
NoRole 
ResetRole 
ApplyRole 
NRoles 

Definition at line 53 of file qmessagebox.h.

◆ Icon

This enum has the following values:

\value NoIcon the message box does not have any icon.

\value Question an icon indicating that the message is asking a question.

\value Information an icon indicating that the message is nothing out of the ordinary.

\value Warning an icon indicating that the message is a warning, but can be dealt with.

\value Critical an icon indicating that the message represents a critical problem.

Enumerator
NoIcon 
Information 
Warning 
Critical 
Question 

Definition at line 43 of file qmessagebox.h.

◆ Option

enum class QMessageBox::Option
strong
Since
6.6 \value DontUseNativeDialog Don't use the native message dialog.
Enumerator
DontUseNativeDialog 

Definition at line 38 of file qmessagebox.h.

◆ StandardButton

Since
4.2

These enums describe flags for standard buttons. Each button has a defined \l ButtonRole.

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

\value NoButton An invalid button.

\omitvalue FirstButton \omitvalue LastButton

The following values are obsolete:

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

Constructor & Destructor Documentation

◆ QMessageBox() [1/2]

QMessageBox::QMessageBox ( QWidget * parent = nullptr)
explicit

Constructs an \l{Qt::ApplicationModal} {application modal} message box with no text and no buttons.

parent is passed to the QDialog constructor.

The window modality can be overridden via setWindowModality() before calling show().

Note
Using open() or exec() to show the message box affects the window modality. Please see the detailed documentation for each function for more information.

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

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

Definition at line 838 of file qmessagebox.cpp.

References d.

Referenced by about(), and aboutQt().

+ Here is the caller graph for this function:

◆ QMessageBox() [2/2]

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

Constructs an \l{Qt::ApplicationModal} {application modal} 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 window modality can be overridden via setWindowModality() before calling show().

Note
Using open() or exec() to show the message box affects the window modality. Please see the detailed documentation for each function for more information.

On \macos, if parent is not \nullptr and you want your message box to appear as a Qt::Sheet of that parent, set the message box's \l{setWindowModality()} {window modality} to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog.

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

Definition at line 863 of file qmessagebox.cpp.

References buttons(), d, icon, NoButton, setIcon(), setStandardButtons(), text, and title.

+ Here is the call graph for this function:

◆ ~QMessageBox()

QMessageBox::~QMessageBox ( )

Destroys the message box.

Definition at line 878 of file qmessagebox.cpp.

Member Function Documentation

◆ about()

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

Displays a simple about box with title title and text text.

The about box's parent is parent.

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

\list 1

The about box has a single button labelled "OK".

On \macos, 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 1945 of file qmessagebox.cpp.

References QMessageBox(), d, QDialog::exec(), icon, Information, msgBox, NoButton, QObject::parent(), QWidget::setAttribute(), setIconPixmap(), QDialog::setModal(), QWidget::show(), text, title, Qt::WA_DeleteOnClose, QWidget::windowIcon, Qt::WindowSystemMenuHint, and Qt::WindowTitleHint.

Referenced by boo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ aboutQt()

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

Displays a simple message box about Qt, with the given title and centered over parent (if parent is not \nullptr).

The message includes the version number of Qt being used by the application.

This is useful for inclusion in the \uicontrol Help menu of an application, as shown in the \l{mainwindows/menus}{Menus} example.

QApplication provides this functionality as a slot.

On \macos, the aboutQt box is popped up as a modeless window; on other platforms, it is currently application modal.

See also
QApplication::aboutQt()

Definition at line 1999 of file qmessagebox.cpp.

References QMessageBox(), QString::arg(), d, QDialog::exec(), QString::isEmpty(), QPixmap::isNull(), msgBox, QObject::parent(), QStringLiteral, QWidget::setAttribute(), setIconPixmap(), setInformativeText(), QDialog::setModal(), setText(), setWindowTitle(), QWidget::show(), title, tr, and Qt::WA_DeleteOnClose.

Referenced by QApplication::aboutQt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addButton() [1/3]

QPushButton * QMessageBox::addButton ( const QString & text,
ButtonRole role )
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.

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

Definition at line 936 of file qmessagebox.cpp.

References addButton(), d, pushButton, QDialog::QPushButton, and text.

+ Here is the call graph for this function:

◆ addButton() [2/3]

void QMessageBox::addButton ( QAbstractButton * button,
ButtonRole role )
Since
4.2

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

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

Definition at line 890 of file qmessagebox.cpp.

References button, d, QString::isEmpty(), QGuiApplicationPrivate::platformTheme(), qWarning, removeButton(), QAbstractButton::setText(), standardButton(), QMessageBoxPrivate::standardButtonForRole(), and QAbstractButton::text.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addButton() [3/3]

QPushButton * QMessageBox::addButton ( StandardButton 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.

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

See also
setStandardButtons()

Definition at line 954 of file qmessagebox.cpp.

References button, d, and pushButton.

◆ button()

QAbstractButton * QMessageBox::button ( StandardButton which) const
Since
4.2

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

Note
Modifying the properties of the returned button may not be reflected in native implementations of the message dialog. To customize dialog buttons add a \l{addButton(QAbstractButton *button, QMessageBox::ButtonRole role)} {custom button} or \l{addButton(const QString &text, QMessageBox::ButtonRole role)} {button title} instead, or set the \l Option::DontUseNativeDialog option.
See also
standardButtons, standardButton()

Definition at line 1041 of file qmessagebox.cpp.

References d.

◆ buttonClicked

void QMessageBox::buttonClicked ( QAbstractButton * button)
signal

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

The button that was clicked in returned in button.

Referenced by QWidgetPlatformMessageDialog::QWidgetPlatformMessageDialog(), and open().

+ Here is the caller graph for this function:

◆ buttonRole()

QMessageBox::ButtonRole QMessageBox::buttonRole ( QAbstractButton * button) const
Since
4.5

Returns the button role for the specified button. This function returns \l InvalidRole if button is \nullptr or has not been added to the message box.

See also
buttons(), addButton()

Definition at line 1725 of file qmessagebox.cpp.

References button, and d.

◆ buttons()

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

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

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

Definition at line 1711 of file qmessagebox.cpp.

References d.

Referenced by QMessageBox(), critical(), information(), keyPressEvent(), question(), setStandardButtons(), and warning().

+ Here is the caller graph for this function:

◆ changeEvent()

void QMessageBox::changeEvent ( QEvent * event)
overrideprotectedvirtual

\reimp

Reimplemented from QWidget.

Definition at line 1556 of file qmessagebox.cpp.

References QEvent::ApplicationFontChange, QWidget::changeEvent(), d, QWidget::font, QEvent::FontChange, NoIcon, Q_FALLTHROUGH, setIcon(), QStyle::SH_MessageBox_CenterButtons, QStyle::SH_MessageBox_TextInteractionFlags, QWidget::style(), and QEvent::StyleChange.

+ Here is the call graph for this function:

◆ checkBox()

QCheckBox * QMessageBox::checkBox ( ) const
Since
5.2

Returns the checkbox shown on the dialog. This is \nullptr if no checkbox is set.

See also
setCheckBox()

Definition at line 1263 of file qmessagebox.cpp.

References d.

◆ clickedButton()

QAbstractButton * QMessageBox::clickedButton ( ) const
Since
4.2

Returns the button that was clicked by the user, or \nullptr if the user hit the \uicontrol Esc key and no \l{setEscapeButton()}{escape button} was set.

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

Example:

See also
standardButton(), button()

Definition at line 1171 of file qmessagebox.cpp.

References d.

Referenced by showNewMessageBox().

+ Here is the caller graph for this function:

◆ closeEvent()

void QMessageBox::closeEvent ( QCloseEvent * event)
overrideprotectedvirtual

\reimp

Reimplemented from QDialog.

Definition at line 1539 of file qmessagebox.cpp.

References QDialog::closeEvent(), d, QEvent::ignore(), and QDialog::setResult().

+ Here is the call graph for this function:

◆ critical()

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

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

The standard buttons are added to the message box. defaultButton specifies the button used when \uicontrol 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 \uicontrol Esc was pressed instead, the \l{Default and Escape Keys} {escape button} is returned.

The message box is an \l{Qt::ApplicationModal} {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 1917 of file qmessagebox.cpp.

References buttons(), Critical, defaultButton(), QObject::parent(), showNewMessageBox(), text, and title.

Referenced by boo(), QQuickWidgetPrivate::handleContextCreationFailure(), and qRequireVersion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ defaultButton()

QPushButton * QMessageBox::defaultButton ( ) const
Since
4.2

Returns the button that should be the message box's \l{QPushButton::setDefault()}{default button}. Returns nullptr if no default button was set.

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

Definition at line 1186 of file qmessagebox.cpp.

References d.

Referenced by critical(), information(), question(), setWindowModality(), showNewMessageBox(), and warning().

+ Here is the caller graph for this function:

◆ escapeButton()

QAbstractButton * QMessageBox::escapeButton ( ) const
Since
4.2

Returns the button that is activated when escape is pressed.

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

\list 1

  • If there is only one button, it is made the escape button.
  • If there is a \l Cancel button, it is made the escape button.
  • On \macos only, if there is exactly one button with the role QMessageBox::RejectRole, it is made the escape button. \endlist

When an escape button could not be automatically detected, pressing \uicontrol Esc has no effect.

See also
addButton()

Definition at line 1067 of file qmessagebox.cpp.

References d.

◆ event()

bool QMessageBox::event ( QEvent * e)
overrideprotectedvirtual

\reimp

Reimplemented from QObject.

Definition at line 1512 of file qmessagebox.cpp.

References QObject::event(), QEvent::LanguageChange, QEvent::LayoutRequest, QDialog::result(), and QEvent::type().

+ Here is the call graph for this function:

◆ icon()

QMessageBox::Icon QMessageBox::icon ( ) const

Definition at line 1417 of file qmessagebox.cpp.

References d.

◆ iconPixmap()

QPixmap QMessageBox::iconPixmap ( ) const

Definition at line 1443 of file qmessagebox.cpp.

References d.

◆ information()

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

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

The standard buttons are added to the message box. defaultButton specifies the button used when \uicontrol 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 \uicontrol Esc was pressed instead, the \l{Default and Escape Keys} {escape button} is returned.

The message box is an \l{Qt::ApplicationModal}{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 1819 of file qmessagebox.cpp.

References buttons(), defaultButton(), Information, QObject::parent(), showNewMessageBox(), text, and title.

Referenced by boo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ informativeText()

QString QMessageBox::informativeText ( ) const

Definition at line 2696 of file qmessagebox.cpp.

References d.

◆ keyPressEvent()

void QMessageBox::keyPressEvent ( QKeyEvent * event)
overrideprotectedvirtual

\reimp

Reimplemented from QDialog.

Definition at line 1590 of file qmessagebox.cpp.

References Qt::AltModifier, button, buttons(), QKeySequence::Cancel, QGuiApplication::clipboard(), Qt::ControlModifier, QKeySequence::Copy, d, QKeyEvent::key(), QDialog::keyPressEvent(), Qt::MetaModifier, QKeyEvent::modifiers(), QKeySequence::SelectAll, QEvent::setAccepted(), shortcut, QAbstractButton::text, and QWidget::windowTitle.

+ Here is the call graph for this function:

◆ open [1/2]

void QDialog::open ( )
slot
Since
4.5

Shows the dialog as a \l{QDialog::Modal Dialogs}{window modal dialog}, returning immediately.

See also
exec(), show(), result(), setWindowModality()

Definition at line 52 of file qdialog.cpp.

◆ open() [2/2]

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.

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 1672 of file qmessagebox.cpp.

References buttonClicked(), QObject::connect(), d, QDialog::finished(), QDialog::open(), SIGNAL, and signal.

+ Here is the call graph for this function:

◆ options()

QMessageBox::Options QMessageBox::options ( ) const

Definition at line 1316 of file qmessagebox.cpp.

References d.

◆ question()

int QMessageBox::question ( QWidget * parent,
const QString & title,
const QString & text,
StandardButtons buttons = StandardButtons(Yes | No),
StandardButton defaultButton = NoButton )
static
Since
4.2

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

The standard buttons are added to the message box. defaultButton specifies the button used when \uicontrol 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 \uicontrol Esc was pressed instead, the \l{Default and Escape Keys} {escape button} is returned.

The message box is an \l{Qt::ApplicationModal} {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()

Needed for Qt 4 source compatibility

Definition at line 1853 of file qmessagebox.cpp.

References buttons(), defaultButton(), QObject::parent(), Question, showNewMessageBox(), text, and title.

Referenced by boo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeButton()

void QMessageBox::removeButton ( QAbstractButton * button)
Since
4.2

Removes button from the button box without deleting it.

See also
addButton(), setStandardButtons()

Definition at line 970 of file qmessagebox.cpp.

References button, and d.

Referenced by addButton().

+ Here is the caller graph for this function:

◆ resizeEvent()

void QMessageBox::resizeEvent ( QResizeEvent * event)
overrideprotectedvirtual

\reimp

Reimplemented from QDialog.

Definition at line 1531 of file qmessagebox.cpp.

References QDialog::resizeEvent().

+ Here is the call graph for this function:

◆ setCheckBox()

void QMessageBox::setCheckBox ( QCheckBox * cb)
Since
5.2

Sets the checkbox cb on the message dialog. The message box takes ownership of the checkbox. The argument cb can be \nullptr to remove an existing checkbox from the message box.

See also
checkBox()

Definition at line 1232 of file qmessagebox.cpp.

References cb, d, QWidget::layout(), QSizePolicy::MinimumExpanding, QLayout::removeWidget(), and sp.

+ Here is the call graph for this function:

◆ setDefaultButton() [1/2]

void QMessageBox::setDefaultButton ( QPushButton * button)
Since
4.2

Sets the message box's \l{QPushButton::setDefault()}{default button} to button.

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

Definition at line 1200 of file qmessagebox.cpp.

References button, d, QPushButton::setDefault(), and QWidget::setFocus().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDefaultButton() [2/2]

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

Sets the message box's \l{QPushButton::setDefault()}{default button} to button.

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

Definition at line 1218 of file qmessagebox.cpp.

References button, d, and setDefaultButton().

+ Here is the call graph for this function:

◆ setEscapeButton() [1/2]

void QMessageBox::setEscapeButton ( QAbstractButton * button)
Since
4.2

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

See also
addButton(), clickedButton()

Definition at line 1081 of file qmessagebox.cpp.

References button, and d.

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

+ Here is the caller graph for this function:

◆ setEscapeButton() [2/2]

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

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

See also
addButton(), clickedButton()

Definition at line 1096 of file qmessagebox.cpp.

References button, d, and setEscapeButton().

+ Here is the call graph for this function:

◆ setIcon()

void QMessageBox::setIcon ( Icon icon)

Definition at line 1423 of file qmessagebox.cpp.

References d, icon, setIconPixmap(), and QMessageBoxPrivate::standardIcon().

Referenced by QMessageBox(), changeEvent(), and QWidgetPlatformMessageDialog::show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setIconPixmap()

void QMessageBox::setIconPixmap ( const QPixmap & pixmap)

Definition at line 1449 of file qmessagebox.cpp.

References d, NoIcon, and pixmap.

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

+ Here is the caller graph for this function:

◆ setInformativeText()

void QMessageBox::setInformativeText ( const QString & text)

Definition at line 2702 of file qmessagebox.cpp.

References Qt::AlignLeft, Qt::AlignTop, d, QString::isEmpty(), qt_app_fonts_hash(), QObject::setObjectName(), QStyle::SH_MessageBox_TextInteractionFlags, QWidget::style(), and text.

Referenced by aboutQt(), and QWidgetPlatformMessageDialog::show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOption()

void QMessageBox::setOption ( Option option,
bool on = true )
Since
6.6 Sets the given option to be enabled if on is true; otherwise, clears the given option.

Options (particularly the \l Option::DontUseNativeDialog option) should be set before showing the dialog.

Setting options while the dialog is visible is not guaranteed to have an immediate effect on the dialog.

Setting options after changing other properties may cause these values to have no effect.

See also
options, testOption()

Definition at line 1285 of file qmessagebox.cpp.

References options, and setOptions().

+ Here is the call graph for this function:

◆ setOptions()

void QMessageBox::setOptions ( Options options)

Definition at line 1306 of file qmessagebox.cpp.

References d, and options.

Referenced by setOption().

+ Here is the caller graph for this function:

◆ setStandardButtons()

void QMessageBox::setStandardButtons ( StandardButtons buttons)

Definition at line 993 of file qmessagebox.cpp.

References buttons(), and d.

Referenced by QMessageBox(), and QWidgetPlatformMessageDialog::show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setText()

void QMessageBox::setText ( const QString & text)

Definition at line 1363 of file qmessagebox.cpp.

References Qt::AutoText, d, Qt::mightBeRichText(), Qt::RichText, and text.

Referenced by aboutQt(), and QWidgetPlatformMessageDialog::show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTextFormat()

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

Definition at line 1474 of file qmessagebox.cpp.

References Qt::AutoText, d, Qt::mightBeRichText(), and Qt::RichText.

+ Here is the call graph for this function:

◆ setTextInteractionFlags()

void QMessageBox::setTextInteractionFlags ( Qt::TextInteractionFlags flags)

Definition at line 1503 of file qmessagebox.cpp.

References d.

◆ setWindowModality()

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

This function shadows QWidget::setWindowModality().

Sets the modality of the message box to windowModality.

On \macos, 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 2762 of file qmessagebox.cpp.

References defaultButton(), Qt::Dialog, QWidget::parentWidget(), setDefaultButton(), QWidget::setParent(), QWidget::setWindowModality(), Qt::Sheet, Qt::WindowModal, and QWidget::windowModality.

+ Here is the call graph for this function:

◆ setWindowTitle()

void QMessageBox::setWindowTitle ( const QString & title)
Since
4.2

This function shadows QWidget::setWindowTitle().

Sets the title of the message box to title. On \macos, the window title is ignored (as required by the \macos Guidelines).

Definition at line 2740 of file qmessagebox.cpp.

References Q_UNUSED, QWidget::setWindowTitle(), and title.

Referenced by aboutQt(), and QWidgetPlatformMessageDialog::show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showEvent()

void QMessageBox::showEvent ( QShowEvent * event)
overrideprotectedvirtual

\reimp

Reimplemented from QDialog.

Definition at line 1734 of file qmessagebox.cpp.

References d, and QDialog::showEvent().

+ Here is the call graph for this function:

◆ standardButton()

QMessageBox::StandardButton QMessageBox::standardButton ( QAbstractButton * button) const
Since
4.2

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

See also
button(), standardButtons()

Definition at line 1021 of file qmessagebox.cpp.

References button, and d.

Referenced by addButton(), and showNewMessageBox().

+ Here is the caller graph for this function:

◆ standardButtons()

QMessageBox::StandardButtons QMessageBox::standardButtons ( ) const

Definition at line 1007 of file qmessagebox.cpp.

References d.

◆ testOption()

bool QMessageBox::testOption ( Option option) const
Since
6.6

Returns true if the given option is enabled; otherwise, returns false.

See also
options, setOption()

Definition at line 1300 of file qmessagebox.cpp.

References d.

◆ text()

QString QMessageBox::text ( ) const

Definition at line 1357 of file qmessagebox.cpp.

References d.

◆ textFormat()

Qt::TextFormat QMessageBox::textFormat ( ) const

Definition at line 1468 of file qmessagebox.cpp.

References d.

◆ textInteractionFlags()

Qt::TextInteractionFlags QMessageBox::textInteractionFlags ( ) const

Definition at line 1497 of file qmessagebox.cpp.

References d.

◆ warning()

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

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

The standard buttons are added to the message box. defaultButton specifies the button used when \uicontrol 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 \uicontrol Esc was pressed instead, the \l{Default and Escape Keys} {escape button} is returned.

The message box is an \l{Qt::ApplicationModal} {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 1885 of file qmessagebox.cpp.

References buttons(), defaultButton(), QObject::parent(), showNewMessageBox(), text, title, and Warning.

Referenced by QPrintPropertiesDialog::accept(), boo(), src_gui_kernel_qguiapplication::MyMainWidget::commitData(), QFileDialogPrivate::deleteCurrent(), QFileDialogPrivate::goToDirectory(), QPrintDialogPrivate::openWindowsPrintDialogModally(), MainWindow::saveFile(), and Viewer::saveImage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Property Documentation

◆ icon

QMessageBox::icon
readwrite

the message box's icon

The icon of the message box can be specified with one of the values:

\list

The default is QMessageBox::NoIcon.

The pixmap used to display the actual icon depends on the current \l{QWidget::style()} {GUI style}. You can also set a custom pixmap for the icon by setting the \l{QMessageBox::iconPixmap} {icon pixmap} property.

See also
iconPixmap

Definition at line 25 of file qmessagebox.h.

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

◆ iconPixmap

QMessageBox::iconPixmap
readwrite

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 26 of file qmessagebox.h.

◆ informativeText

QMessageBox::informativeText
readwrite

the informative text that provides a fuller description for the message

Since
4.2

Informative text can be used to expand upon the text() to give more information to the user, for example describing the consequences of the situation, or suggestion alternative solutions.

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

By default, this property contains an empty string.

See also
textFormat, QMessageBox::text, QMessageBox::detailedText

Definition at line 32 of file qmessagebox.h.

◆ options

QMessageBox::options
readwrite

Options that affect the look and feel of the dialog.

Since
6.6

By default, these options are disabled.

The option \l Option::DontUseNativeDialog should be set before changing dialog properties or showing the dialog.

Setting options while the dialog is visible is not guaranteed to have an immediate effect on the dialog.

Setting options after changing other properties may cause these values to have no effect.

See also
setOption(), testOption()

Definition at line 35 of file qmessagebox.h.

Referenced by setOption(), and setOptions().

◆ standardButtons

QMessageBox::standardButtons
readwrite

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 28 of file qmessagebox.h.

◆ text

QMessageBox::text
readwrite

the message box text to be displayed.

The text should be a brief sentence or phrase that describes the situation, ideally formulated as a neutral statement, or a call-to-action question.

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

The default value of this property is an empty string.

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

Definition at line 24 of file qmessagebox.h.

Referenced by QMessageBox(), about(), addButton(), critical(), information(), question(), setInformativeText(), setText(), and warning().

◆ textFormat

QMessageBox::textFormat
readwrite

the format of the text displayed by the message box

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

The default format is Qt::AutoText.

See also
setText()

Definition at line 27 of file qmessagebox.h.

◆ textInteractionFlags

QMessageBox::textInteractionFlags
readwrite
Since
5.1

Specifies how the label of the message box should interact with user input.

The default value depends on the style.

See also
QStyle::SH_MessageBox_TextInteractionFlags

Definition at line 33 of file qmessagebox.h.


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