QMessageBox#

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

Inheritance diagram of PySide6.QtWidgets.QMessageBox

Synopsis#

Properties#

Functions#

Signals#

Static functions#

  • def about (parent, title, text)

  • def aboutQt (parent[, title=””])

  • def critical (parent, title, text[, buttons=QMessageBox.StandardButton.Ok[, defaultButton=QMessageBox.StandardButton.NoButton]])

  • def critical (parent, title, text, button0, button1)

  • def information (parent, title, text[, buttons=QMessageBox.StandardButton.Ok[, defaultButton=QMessageBox.StandardButton.NoButton]])

  • def information (parent, title, text, button0[, button1=QMessageBox.StandardButton.NoButton])

  • def question (parent, title, text[, buttons=QMessageBox.StandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)[, defaultButton=QMessageBox.StandardButton.NoButton]])

  • def question (parent, title, text, button0, button1)

  • def standardIcon (icon)

  • def warning (parent, title, text[, buttons=QMessageBox.StandardButton.Ok[, defaultButton=QMessageBox.StandardButton.NoButton]])

  • def warning (parent, title, text, button0, button1)

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

A message box displays a primary text to alert the user to a situation, an informative text to further explain the situation, 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 = QMessageBox()
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.

../../_images/msgbox1.png

A better approach than just alerting the user to an event is to also ask the user what to do about it.

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 macOS, the order is reversed. Mark one of your standard buttons to be your default button .

The informative text property can be used to add additional context to help the user choose the appropriate action.

msgBox = QMessageBox()
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)
ret = msgBox.exec()
../../_images/msgbox2.png

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

if ret == QMessageBox.Save:
    # Save was clicked
    break
elif ret == QMessageBox.Discard:
    # Don't Save was clicked
    break
elif ret == QMessageBox.Cancel:
    # Cancel was clicked
    break
else:
    # should never be reached
    break

To give the user more information to help them choose the appropriate, action, set the detailed text property. Depending on the platform the detailed text , may require the user to click a Show Details… button to be shown.

../../_images/msgbox3.png

Clicking the Show Details… button displays the detailed text.

../../_images/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 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:

../../_images/qmessagebox-quest.png

Question

For asking a question during normal operations.

../../_images/qmessagebox-info.png

Information

For reporting information about normal operations.

../../_images/qmessagebox-warn.png

Warning

For reporting non-critical errors.

../../_images/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.

ret = QMessageBox.warning(self, 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.

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 ButtonRole 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,

msgBox = QMessageBox()
connectButton = msgBox.addButton(tr("Connect"), QMessageBox.ActionRole)
abortButton = msgBox.addButton(QMessageBox.Abort)
msgBox.exec()
if msgBox.clickedButton() == connectButton:
    # connect
 elif msgBox.clickedButton() == abortButton:
    # abort

Default and Escape Keys#

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

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

  1. If there is only one button, it is the button activated when Esc is pressed.

  2. If there is a Cancel button, it is the button activated when Esc is pressed.

  3. If there is exactly one button having either the Reject role or the the No role , it is the button activated when Esc is pressed.

When an escape button can’t be determined using these rules, pressing Esc has no effect.

See also

QDialogButtonBox Standard Dialogs Example Qt Widgets - Application Example

class PySide6.QtWidgets.QMessageBox(icon, title, text[, buttons=QMessageBox.StandardButton.NoButton[, parent=None[, flags=Qt.Dialog | Qt.MSWindowsFixedSizeDialogHint]]])#

PySide6.QtWidgets.QMessageBox([parent=None])

Parameters:

Constructs an 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 None and you want your message box to appear as a Sheet of that parent, set the message box’s window modality to WindowModal (default). Otherwise, the message box will be a standard dialog.

Constructs an 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 Sheet of its parent, set the message box’s window modality to WindowModal or use open() . Otherwise, the message box will be a standard dialog.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtWidgets.QMessageBox.detailedText: str#

This property holds the text to be displayed in the details area..

The text will be interpreted as a plain text.

By default, this property contains an empty string.

Access functions:
property PᅟySide6.QtWidgets.QMessageBox.icon: Icon#

This property holds the message box’s icon.

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

  • NoIcon

  • Question

  • Information

  • Warning

  • Critical

The default is NoIcon .

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

See also

iconPixmap

Access functions:
property PᅟySide6.QtWidgets.QMessageBox.iconPixmap: PySide6.QtGui.QPixmap#

This property holds the current icon.

The icon currently used by the message box. Note that it’s often hard to draw one pixmap that looks appropriate in all GUI styles; you may want to supply a different pixmap for each platform.

By default, this property is undefined.

See also

icon

Access functions:
property PᅟySide6.QtWidgets.QMessageBox.informativeText: str#

This property holds the informative text that provides a fuller description for the message.

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.

By default, this property contains an empty string.

See also

text detailedText

Access functions:
property PᅟySide6.QtWidgets.QMessageBox.standardButtons: StandardButtons#

This property holds collection of standard buttons in the message box.

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

By default, this property contains no standard buttons.

See also

addButton()

Access functions:
property PᅟySide6.QtWidgets.QMessageBox.text: str#

This property holds 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 ( 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 an empty string.

Access functions:
property PᅟySide6.QtWidgets.QMessageBox.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 TextFormat enum for an explanation of the possible options.

The default format is AutoText .

See also

setText()

Access functions:
property PᅟySide6.QtWidgets.QMessageBox.textInteractionFlags: TextInteractionFlags#

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

The default value depends on the style.

See also

SH_MessageBox_TextInteractionFlags

Access functions:
PySide6.QtWidgets.QMessageBox.Icon#

This enum has the following values:

Constant

Description

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.

PySide6.QtWidgets.QMessageBox.ButtonRole#

This enum describes the roles that can be used to describe buttons in the button box. Combinations of these roles are as flags used to describe different aspects of their behavior.

Constant

Description

QMessageBox.InvalidRole

The button is invalid.

QMessageBox.AcceptRole

Clicking the button causes the dialog to be accepted (e.g. OK).

QMessageBox.RejectRole

Clicking the button causes the dialog to be rejected (e.g. Cancel).

QMessageBox.DestructiveRole

Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog.

QMessageBox.ActionRole

Clicking the button causes changes to the elements within the dialog.

QMessageBox.HelpRole

The button can be clicked to request help.

QMessageBox.YesRole

The button is a “Yes”-like button.

QMessageBox.NoRole

The button is a “No”-like button.

QMessageBox.ApplyRole

The button applies current changes.

QMessageBox.ResetRole

The button resets the dialog’s fields to default values.

See also

StandardButton

PySide6.QtWidgets.QMessageBox.StandardButton#

(inherits enum.IntFlag) These enums describe flags for standard buttons. Each button has a defined ButtonRole .

Constant

Description

QMessageBox.Ok

An “OK” button defined with the AcceptRole .

QMessageBox.Open

An “Open” button defined with the AcceptRole .

QMessageBox.Save

A “Save” button defined with the AcceptRole .

QMessageBox.Cancel

A “Cancel” button defined with the RejectRole .

QMessageBox.Close

A “Close” button defined with the RejectRole .

QMessageBox.Discard

A “Discard” or “Don’t Save” button, depending on the platform, defined with the DestructiveRole .

QMessageBox.Apply

An “Apply” button defined with the ApplyRole .

QMessageBox.Reset

A “Reset” button defined with the ResetRole .

QMessageBox.RestoreDefaults

A “Restore Defaults” button defined with the ResetRole .

QMessageBox.Help

A “Help” button defined with the HelpRole .

QMessageBox.SaveAll

A “Save All” button defined with the AcceptRole .

QMessageBox.Yes

A “Yes” button defined with the YesRole .

QMessageBox.YesToAll

A “Yes to All” button defined with the YesRole .

QMessageBox.No

A “No” button defined with the NoRole .

QMessageBox.NoToAll

A “No to All” button defined with the NoRole .

QMessageBox.Abort

An “Abort” button defined with the RejectRole .

QMessageBox.Retry

A “Retry” button defined with the AcceptRole .

QMessageBox.Ignore

An “Ignore” button defined with the AcceptRole .

QMessageBox.NoButton

An invalid button.

The following values are obsolete:

Constant

Description

QMessageBox.YesAll

Use YesToAll instead.

QMessageBox.NoAll

Use NoToAll instead.

QMessageBox.Default

Use the defaultButton argument of information() , warning() , etc. instead, or call setDefaultButton() .

QMessageBox.Escape

Call setEscapeButton() instead.

QMessageBox.FlagMask

QMessageBox.ButtonMask

See also

ButtonRole standardButtons

static PySide6.QtWidgets.QMessageBox.about(parent, title, text)#
Parameters:

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 PySide6.QtWidgets.QApplication.activeWindow()

  4. As a last resort it uses the Information icon.

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.

static PySide6.QtWidgets.QMessageBox.aboutQt(parent[, title=""])#
Parameters:

Displays a simple message box about Qt, with the given title and centered over parent (if parent is not None). 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 macOS, the about box is popped up as a modeless window; on other platforms, it is currently application modal.

See also

aboutQt()

PySide6.QtWidgets.QMessageBox.addButton(button)#
Parameters:

buttonStandardButton

Return type:

PySide6.QtWidgets.QPushButton

This is an overloaded function.

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

PySide6.QtWidgets.QMessageBox.addButton(text, role)
Parameters:
Return type:

PySide6.QtWidgets.QPushButton

This is an overloaded function.

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

PySide6.QtWidgets.QMessageBox.addButton(button, role)
Parameters:

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

PySide6.QtWidgets.QMessageBox.button(which)#
Parameters:

whichStandardButton

Return type:

PySide6.QtWidgets.QAbstractButton

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

PySide6.QtWidgets.QMessageBox.buttonClicked(button)#
Parameters:

buttonPySide6.QtWidgets.QAbstractButton

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

PySide6.QtWidgets.QMessageBox.buttonRole(button)#
Parameters:

buttonPySide6.QtWidgets.QAbstractButton

Return type:

ButtonRole

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

PySide6.QtWidgets.QMessageBox.buttonText(button)#
Parameters:

button – int

Return type:

str

Note

This function is deprecated.

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 text() instead.

See also

setButtonText()

PySide6.QtWidgets.QMessageBox.buttons()#

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

PySide6.QtWidgets.QMessageBox.checkBox()#
Return type:

PySide6.QtWidgets.QCheckBox

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

See also

setCheckBox()

PySide6.QtWidgets.QMessageBox.clickedButton()#
Return type:

PySide6.QtWidgets.QAbstractButton

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

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

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

Example:

messageBox = QMessageBox(self)
disconnectButton =
      messageBox.addButton(tr("Disconnect"), QMessageBox.ActionRole)
...
messageBox.exec()
if messageBox.clickedButton() == disconnectButton:
    ...
static PySide6.QtWidgets.QMessageBox.critical(parent, title, text[, buttons=QMessageBox.StandardButton.Ok[, defaultButton=QMessageBox.StandardButton.NoButton]])#
Parameters:
Return type:

StandardButton

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 Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is NoButton , QMessageBox chooses a suitable default automatically.

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

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.

static PySide6.QtWidgets.QMessageBox.critical(parent, title, text, button0, button1)
Parameters:
Return type:

int

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 Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is NoButton , QMessageBox chooses a suitable default automatically.

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

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.

PySide6.QtWidgets.QMessageBox.defaultButton()#
Return type:

PySide6.QtWidgets.QPushButton

Returns the button that should be the message box’s default button . Returns nullptr if no default button was set.

PySide6.QtWidgets.QMessageBox.detailedText()#
Return type:

str

Getter of property detailedText .

PySide6.QtWidgets.QMessageBox.escapeButton()#
Return type:

PySide6.QtWidgets.QAbstractButton

Returns the button that is activated when escape is pressed.

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

  1. If there is only one button, it is made the escape button.

  2. If there is a Cancel button, it is made the escape button.

  3. On macOS only, if there is exactly one button with the role RejectRole , it is made the escape button.

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

PySide6.QtWidgets.QMessageBox.icon()#
Return type:

Icon

See also

setIcon()

Getter of property icon .

PySide6.QtWidgets.QMessageBox.iconPixmap()#
Return type:

PySide6.QtGui.QPixmap

See also

setIconPixmap()

Getter of property iconPixmap .

static PySide6.QtWidgets.QMessageBox.information(parent, title, text[, buttons=QMessageBox.StandardButton.Ok[, defaultButton=QMessageBox.StandardButton.NoButton]])#
Parameters:
Return type:

StandardButton

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 Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is NoButton , QMessageBox chooses a suitable default automatically.

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

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.

static PySide6.QtWidgets.QMessageBox.information(parent, title, text, button0[, button1=QMessageBox.StandardButton.NoButton])
Parameters:
Return type:

StandardButton

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 Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is NoButton , QMessageBox chooses a suitable default automatically.

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

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.

PySide6.QtWidgets.QMessageBox.informativeText()#
Return type:

str

Getter of property informativeText .

PySide6.QtWidgets.QMessageBox.open(receiver, member)#
Parameters:

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.

static PySide6.QtWidgets.QMessageBox.question(parent, title, text[, buttons=QMessageBox.StandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)[, defaultButton=QMessageBox.StandardButton.NoButton]])#
Parameters:
Return type:

StandardButton

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 Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is NoButton , QMessageBox chooses a suitable default automatically.

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

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.

static PySide6.QtWidgets.QMessageBox.question(parent, title, text, button0, button1)
Parameters:
Return type:

int

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 Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is NoButton , QMessageBox chooses a suitable default automatically.

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

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.

PySide6.QtWidgets.QMessageBox.removeButton(button)#
Parameters:

buttonPySide6.QtWidgets.QAbstractButton

Removes button from the button box without deleting it.

PySide6.QtWidgets.QMessageBox.setButtonText(button, text)#
Parameters:
  • button – int

  • text – str

Note

This function is deprecated.

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.

See also

buttonText()

PySide6.QtWidgets.QMessageBox.setCheckBox(cb)#
Parameters:

cbPySide6.QtWidgets.QCheckBox

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

See also

checkBox()

PySide6.QtWidgets.QMessageBox.setDefaultButton(button)#
Parameters:

buttonStandardButton

Sets the message box’s default button to button.

PySide6.QtWidgets.QMessageBox.setDefaultButton(button)
Parameters:

buttonPySide6.QtWidgets.QPushButton

Sets the message box’s default button to button.

PySide6.QtWidgets.QMessageBox.setDetailedText(text)#
Parameters:

text – str

See also

detailedText()

Setter of property detailedText .

PySide6.QtWidgets.QMessageBox.setEscapeButton(button)#
Parameters:

buttonPySide6.QtWidgets.QAbstractButton

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

PySide6.QtWidgets.QMessageBox.setEscapeButton(button)
Parameters:

buttonStandardButton

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

PySide6.QtWidgets.QMessageBox.setIcon(arg__1)#
Parameters:

arg__1Icon

See also

icon()

Setter of property icon .

PySide6.QtWidgets.QMessageBox.setIconPixmap(pixmap)#
Parameters:

pixmapPySide6.QtGui.QPixmap

See also

iconPixmap()

Setter of property iconPixmap .

PySide6.QtWidgets.QMessageBox.setInformativeText(text)#
Parameters:

text – str

Setter of property informativeText .

PySide6.QtWidgets.QMessageBox.setStandardButtons(buttons)#
Parameters:

buttonsStandardButtons

PySide6.QtWidgets.QMessageBox.setText(text)#
Parameters:

text – str

See also

text()

Setter of property text .

PySide6.QtWidgets.QMessageBox.setTextFormat(format)#
Parameters:

formatTextFormat

See also

textFormat()

Setter of property textFormat .

PySide6.QtWidgets.QMessageBox.setTextInteractionFlags(flags)#
Parameters:

flagsTextInteractionFlags

Setter of property textInteractionFlags .

PySide6.QtWidgets.QMessageBox.setWindowModality(windowModality)#
Parameters:

windowModalityWindowModality

This function shadows setWindowModality() .

Sets the modality of the message box to windowModality.

On macOS, if the modality is set to WindowModal and the message box has a parent, then the message box will be a Sheet , otherwise the message box will be a standard dialog.

PySide6.QtWidgets.QMessageBox.setWindowTitle(title)#
Parameters:

title – str

This function shadows setWindowTitle() .

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

PySide6.QtWidgets.QMessageBox.standardButton(button)#
Parameters:

buttonPySide6.QtWidgets.QAbstractButton

Return type:

StandardButton

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

PySide6.QtWidgets.QMessageBox.standardButtons()#
Return type:

StandardButtons

static PySide6.QtWidgets.QMessageBox.standardIcon(icon)#
Parameters:

iconIcon

Return type:

PySide6.QtGui.QPixmap

Note

This function is deprecated.

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

Call standardIcon() with SP_MessageBoxInformation etc. instead.

PySide6.QtWidgets.QMessageBox.text()#
Return type:

str

See also

setText()

Getter of property text .

PySide6.QtWidgets.QMessageBox.textFormat()#
Return type:

TextFormat

See also

setTextFormat()

Getter of property textFormat .

PySide6.QtWidgets.QMessageBox.textInteractionFlags()#
Return type:

TextInteractionFlags

Getter of property textInteractionFlags .

static PySide6.QtWidgets.QMessageBox.warning(parent, title, text[, buttons=QMessageBox.StandardButton.Ok[, defaultButton=QMessageBox.StandardButton.NoButton]])#
Parameters:
Return type:

StandardButton

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 Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is NoButton , QMessageBox chooses a suitable default automatically.

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

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.

static PySide6.QtWidgets.QMessageBox.warning(parent, title, text, button0, button1)
Parameters:
Return type:

int

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 Enter is pressed. defaultButton must refer to a button that was given in buttons. If defaultButton is NoButton , QMessageBox chooses a suitable default automatically.

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

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.