.BI "TextFormat \fBtextFormat\fR - the format of the text displayed by the message box"
.br
.in -1c
.SH DESCRIPTION
The QMessageBox class provides a modal dialog with a short message, an icon, and some buttons.
.PP
Message boxes are used to provide informative messages and to ask simple questions.
.PP
QMessageBox provides a range of different messages, arranged roughly along two axes: severity and complexity.
.PP
Severity is <center>.nf
.TS
l - l. Question For message boxes that ask a question as part of normal operation. Some style guides recommend using Information for this purpose. Information For message boxes that are part of normal operation. Warning For message boxes that tell the user about unusual errors. Critical
.TE
.fi
</center>
.PP
The message box has a different icon for each of the severity levels.
.PP
Complexity is one button (OK) for simple messages, or two or even three buttons for questions.
.PP
There are static functions for the most common cases.
.PP
Examples:
.)l
.PP
If a program is unable to find a supporting file, but can do perfectly well without it:
case 0: // The user clicked the Retry again button or pressed Enter
.br
// try again
.br
break;
.br
case 1: // The user clicked the Quit or pressed Escape
.br
// exit
.br
break;
.br
}
.br
.fi
.PP
The text part of all message box messages can be either rich text or plain text. If you specify a rich text formatted string, it will be rendered using the default stylesheet. See QStyleSheet::defaultSheet() for details. With certain strings that contain XML meta characters, the auto-rich text detection may fail, interpreting plain text incorrectly as rich text. In these rare cases, use QStyleSheet::convertFromPlainText() to convert your plain text string to a visually equivalent rich text string or set the text format explicitly with setTextFormat().
.PP
Note that the Microsoft Windows User Interface Guidelines recommend using the application name as the window's caption.
.PP
Below are more examples of how to use the static member functions. After these examples you will find an overview of the non-static member functions.
.PP
Exiting a program is part of its normal operation. If there is unsaved data the user probably should be asked if they want to save the data. For example:
.PP
.nf
.br
switch( QMessageBox::information( this, "Application name here",
.br
"The document contains unsaved changes\\n"
.br
"Do you want to save the changes before exiting?",
.br
"&Save", "&Discard", "Cancel",
.br
0, // Enter == button 0
.br
2 ) ) { // Escape == button 2
.br
case 0: // Save clicked or Alt+S pressed or Enter pressed.
.br
// save
.br
break;
.br
case 1: // Discard clicked or Alt+D pressed
.br
// don't save but exit
.br
break;
.br
case 2: // Cancel clicked or Escape pressed
.br
// don't exit
.br
break;
.br
}
.br
.fi
.PP
The Escape button cancels the entire exit operation, and pressing Enter causes the changes to be saved before the exit occurs.
.PP
Disk full errors are unusual and they certainly can be hard to correct. This example uses predefined buttons instead of hard-coded button texts:
.PP
.nf
.br
switch( QMessageBox::warning( this, "Application name here",
.br
"Could not save the user preferences,\\n"
.br
"because the disk is full. You can delete\\n"
.br
"some files and press Retry, or you can\\n"
.br
"abort the Save Preferences operation.",
.br
QMessageBox::Retry | QMessageBox::Default,
.br
QMessageBox::Abort | QMessageBox::Escape )) {
.br
case QMessageBox::Retry: // Retry clicked or Enter pressed
.br
// try again
.br
break;
.br
case QMessageBox::Abort: // Abort clicked or Escape pressed
The critical() function should be reserved for critical errors. In this example errorDetails is a TQString or const char*, and TQString is used to concatenate several strings:
If you want your users to know that the application is built using TQt (so they know that you use high quality tools) you might like to add an "About Qt" menu option under the Help menu to invoke aboutTQt().
If none of the standard message boxes is suitable, you can create a QMessageBox from scratch and use custom button texts:
.PP
.nf
.br
QMessageBox mb( "Application name here",
.br
"Saving the file will overwrite the original file on the disk.\\n"
.br
"Do you really want to save?",
.br
QMessageBox::Information,
.br
QMessageBox::Yes | QMessageBox::Default,
.br
QMessageBox::No,
.br
QMessageBox::Cancel | QMessageBox::Escape );
.br
mb.setButtonText( QMessageBox::Yes, "Save" );
.br
mb.setButtonText( QMessageBox::No, "Discard" );
.br
switch( mb.exec() ) {
.br
case QMessageBox::Yes:
.br
// save and exit
.br
break;
.br
case QMessageBox::No:
.br
// exit without saving
.br
break;
.br
case QMessageBox::Cancel:
.br
// don't save and don't exit
.br
break;
.br
}
.br
.fi
.PP
QMessageBox defines two enum types: Icon and an unnamed button type. Icon defines the Question, Information, Warning, and Critical icons for each GUI style. It is used by the constructor and by the static member functions question(), information(), warning() and critical(). A function called standardIcon() gives you access to the various icons.
.PP
The button types are:
.TP
Ok - the default for single-button message boxes
.TP
Cancel - note that this is \fInot\fR automatically Escape
.TP
Yes
.TP
No
.TP
Abort
.TP
Retry
.TP
Ignore
.TP
YesAll
.TP
NoAll
.PP
Button types can be combined with two modifiers by using OR, '|':
.TP
Default - makes pressing Enter equivalent to clicking this button. Normally used with Ok, Yes or similar.
.TP
Escape - makes pressing Escape equivalent to clicking this button. Normally used with Abort, Cancel or similar.
.PP
The text(), icon() and iconPixmap() functions provide access to the current text and pixmap of the message box. The setText(), setIcon() and setIconPixmap() let you change it. The difference between setIcon() and setIconPixmap() is that the former accepts a QMessageBox::Icon and can be used to set standard icons, whereas the latter accepts a QPixmap and can be used to set custom icons.
.PP
setButtonText() and buttonText() provide access to the buttons.
.PP
QMessageBox has no signals or slots.
.PP
.ce 1
.B "[Image Omitted]"
.PP
.ce 1
.B "[Image Omitted]"
.PP
See also QDialog, Isys on error messages, GUI Design Handbook: Message Box, and Dialog Classes.
.SS "Member Type Documentation"
.SH "QMessageBox::Icon"
This enum has the following values:
.TP
\fCQMessageBox::NoIcon\fR - the message box does not have any icon.
.TP
\fCQMessageBox::Question\fR - an icon indicating that the message is asking a question.
.TP
\fCQMessageBox::Information\fR - an icon indicating that the message is nothing out of the ordinary.
.TP
\fCQMessageBox::Warning\fR - an icon indicating that the message is a warning, but can be dealt with.
.TP
\fCQMessageBox::Critical\fR - an icon indicating that the message represents a critical problem.
Constructs a message box with no text and a button with the label" OK".
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
The \fIparent\fR and \fIname\fR arguments are passed to the QDialog constructor.
Constructs a message box with a \fIcaption\fR, a \fItext\fR, an \fIicon\fR, and up to three buttons.
.PP
The \fIicon\fR must be one of the following:
.TP
QMessageBox::NoIcon
.TP
QMessageBox::Question
.TP
QMessageBox::Information
.TP
QMessageBox::Warning
.TP
QMessageBox::Critical
.PP
Each button, \fIbutton0\fR, \fIbutton1\fR and \fIbutton2\fR, can have one of the following values:
.TP
QMessageBox::NoButton
.TP
QMessageBox::Ok
.TP
QMessageBox::Cancel
.TP
QMessageBox::Yes
.TP
QMessageBox::No
.TP
QMessageBox::Abort
.TP
QMessageBox::Retry
.TP
QMessageBox::Ignore
.TP
QMessageBox::YesAll
.TP
QMessageBox::NoAll
.PP
Use QMessageBox::NoButton for the later parameters to have fewer than three buttons in your message box. If you don't specify any buttons at all, QMessageBox will provide an Ok button.
.PP
One of the buttons can be OR-ed with the \fCQMessageBox::Default\fR flag to make it the default button (clicked when Enter is pressed).
.PP
One of the buttons can be OR-ed with the \fCQMessageBox::Escape\fR flag to make it the cancel or close button (clicked when Escape is pressed).
.PP
Example:
.PP
.nf
.br
QMessageBox mb( "Application Name",
.br
"Hardware failure.\\n\\nDisk error detected\\nDo you want to stop?",
.br
QMessageBox::Question,
.br
QMessageBox::Yes | QMessageBox::Default,
.br
QMessageBox::No | QMessageBox::Escape,
.br
QMessageBox::NoButton );
.br
if ( mb.exec() == QMessageBox::No )
.br
// try again
.br
.fi
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
If \fImodal\fR is TRUE the message box is modal; otherwise it is modeless.
.PP
The \fIparent\fR, \fIname\fR, \fImodal\fR, and \fIf\fR arguments are passed to the QDialog constructor.
Displays a simple message box about Qt, with caption \fIcaption\fR and centered over \fIparent\fR (if \fIparent\fR is not 0). The message includes the version number of TQt being used by the application.
Opens a critical message box with the caption \fIcaption\fR and the text \fItext\fR. The dialog may have up to three buttons. Each of the button parameters, \fIbutton0\fR, \fIbutton1\fR and \fIbutton2\fR may be set to one of the following values:
.TP
QMessageBox::NoButton
.TP
QMessageBox::Ok
.TP
QMessageBox::Cancel
.TP
QMessageBox::Yes
.TP
QMessageBox::No
.TP
QMessageBox::Abort
.TP
QMessageBox::Retry
.TP
QMessageBox::Ignore
.TP
QMessageBox::YesAll
.TP
QMessageBox::NoAll
.PP
If you don't want all three buttons, set the last button, or last two buttons to QMessageBox::NoButton.
.PP
One button can be OR-ed with \fCQMessageBox::Default\fR, and one button can be OR-ed with \fCQMessageBox::Escape\fR.
.PP
Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.) of the button that was clicked.
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
See also information(), question(), and warning().
.PP
Examples:
.)l network/archivesearch/archivedialog.ui.h, network/ftpclient/ftpmainwindow.ui.h, process/process.cpp, and xml/outliner/outlinetree.cpp.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Displays a critical error message box with a caption, a text, and 1, 2 or 3 buttons. Returns the number of the button that was clicked (0, 1 or 2).
.PP
\fIbutton0Text\fR is the text of the first button, and is optional. If \fIbutton0Text\fR is not supplied, "OK" (translated) will be used. \fIbutton1Text\fR is the text of the second button, and is optional, and \fIbutton2Text\fR is the text of the third button, and is optional. \fIdefaultButtonNumber\fR (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). \fIescapeButtonNumber\fR is the index of the Escape button; pressing Escape is the same as clicking this button. It defaults to -1; supply 0, 1, or 2 to make pressing Escape equivalent to clicking the relevant button.
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
See also information(), question(), and warning().
.SH "Icon QMessageBox::icon () const"
Returns the message box's icon. See the "icon" property for details.
Opens an information message box with the caption \fIcaption\fR and the text \fItext\fR. The dialog may have up to three buttons. Each of the buttons, \fIbutton0\fR, \fIbutton1\fR and \fIbutton2\fR may be set to one of the following values:
.TP
QMessageBox::NoButton
.TP
QMessageBox::Ok
.TP
QMessageBox::Cancel
.TP
QMessageBox::Yes
.TP
QMessageBox::No
.TP
QMessageBox::Abort
.TP
QMessageBox::Retry
.TP
QMessageBox::Ignore
.TP
QMessageBox::YesAll
.TP
QMessageBox::NoAll
.PP
If you don't want all three buttons, set the last button, or last two buttons to QMessageBox::NoButton.
.PP
One button can be OR-ed with \fCQMessageBox::Default\fR, and one button can be OR-ed with \fCQMessageBox::Escape\fR.
.PP
Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.) of the button that was clicked.
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
See also question(), warning(), and critical().
.PP
Examples:
.)l action/application.cpp, application/application.cpp, dirview/dirview.cpp, fileiconview/qfileiconview.cpp, picture/picture.cpp, qwerty/qwerty.cpp, and simple/main.cpp.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Displays an information message box with caption \fIcaption\fR, text \fItext\fR and one, two or three buttons. Returns the index of the button that was clicked (0, 1 or 2).
.PP
\fIbutton0Text\fR is the text of the first button, and is optional. If \fIbutton0Text\fR is not supplied, "OK" (translated) will be used. \fIbutton1Text\fR is the text of the second button, and is optional. \fIbutton2Text\fR is the text of the third button, and is optional. \fIdefaultButtonNumber\fR (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). \fIescapeButtonNumber\fR is the index of the Escape button; pressing Escape is the same as clicking this button. It defaults to -1; supply 0, 1 or 2 to make pressing Escape equivalent to clicking the relevant button.
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
Note: If you do not specify an Escape button then if the Escape button is pressed then -1 will be returned. It is suggested that you specify an Escape button to prevent this from happening.
Opens a question message box with the caption \fIcaption\fR and the text \fItext\fR. The dialog may have up to three buttons. Each of the buttons, \fIbutton0\fR, \fIbutton1\fR and \fIbutton2\fR may be set to one of the following values:
.TP
QMessageBox::NoButton
.TP
QMessageBox::Ok
.TP
QMessageBox::Cancel
.TP
QMessageBox::Yes
.TP
QMessageBox::No
.TP
QMessageBox::Abort
.TP
QMessageBox::Retry
.TP
QMessageBox::Ignore
.TP
QMessageBox::YesAll
.TP
QMessageBox::NoAll
.PP
If you don't want all three buttons, set the last button, or last two buttons to QMessageBox::NoButton.
.PP
One button can be OR-ed with \fCQMessageBox::Default\fR, and one button can be OR-ed with \fCQMessageBox::Escape\fR.
.PP
Returns the identity (QMessageBox::Yes, or QMessageBox::No, etc.) of the button that was clicked.
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
See also information(), warning(), and critical().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Displays a question message box with caption \fIcaption\fR, text \fItext\fR and one, two or three buttons. Returns the index of the button that was clicked (0, 1 or 2).
.PP
\fIbutton0Text\fR is the text of the first button, and is optional. If \fIbutton0Text\fR is not supplied, "OK" (translated) will be used. \fIbutton1Text\fR is the text of the second button, and is optional. \fIbutton2Text\fR is the text of the third button, and is optional. \fIdefaultButtonNumber\fR (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). \fIescapeButtonNumber\fR is the index of the Escape button; pressing Escape is the same as clicking this button. It defaults to -1; supply 0, 1 or 2 to make pressing Escape equivalent to clicking the relevant button.
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
Note: If you do not specify an Escape button then if the Escape button is pressed then -1 will be returned. It is suggested that you specify an Escape button to prevent this from happening.
.PP
See also information(), warning(), and critical().
Returns the pixmap used for a standard icon. This allows the pixmaps to be used in more complex message boxes. \fIicon\fR specifies the required icon, e.g. QMessageBox::Question, QMessageBox::Information, QMessageBox::Warning or QMessageBox::Critical.
Returns the pixmap used for a standard icon. This allows the pixmaps to be used in more complex message boxes. \fIicon\fR specifies the required icon, e.g. QMessageBox::Information, QMessageBox::Warning or QMessageBox::Critical.
Opens a warning message box with the caption \fIcaption\fR and the text \fItext\fR. The dialog may have up to three buttons. Each of the button parameters, \fIbutton0\fR, \fIbutton1\fR and \fIbutton2\fR may be set to one of the following values:
.TP
QMessageBox::NoButton
.TP
QMessageBox::Ok
.TP
QMessageBox::Cancel
.TP
QMessageBox::Yes
.TP
QMessageBox::No
.TP
QMessageBox::Abort
.TP
QMessageBox::Retry
.TP
QMessageBox::Ignore
.TP
QMessageBox::YesAll
.TP
QMessageBox::NoAll
.PP
If you don't want all three buttons, set the last button, or last two buttons to QMessageBox::NoButton.
.PP
One button can be OR-ed with \fCQMessageBox::Default\fR, and one button can be OR-ed with \fCQMessageBox::Escape\fR.
.PP
Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.) of the button that was clicked.
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
See also information(), question(), and critical().
.PP
Examples:
.)l chart/chartform.cpp, i18n/main.cpp, network/mail/smtp.cpp, qwerty/qwerty.cpp, showimg/showimg.cpp, and sound/sound.cpp.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Displays a warning message box with a caption, a text, and 1, 2 or 3 buttons. Returns the number of the button that was clicked (0, 1, or 2).
.PP
\fIbutton0Text\fR is the text of the first button, and is optional. If \fIbutton0Text\fR is not supplied, "OK" (translated) will be used. \fIbutton1Text\fR is the text of the second button, and is optional, and \fIbutton2Text\fR is the text of the third button, and is optional. \fIdefaultButtonNumber\fR (0, 1 or 2) is the index of the default button; pressing Return or Enter is the same as clicking the default button. It defaults to 0 (the first button). \fIescapeButtonNumber\fR is the index of the Escape button; pressing Escape is the same as clicking this button. It defaults to -1; supply 0, 1, or 2 to make pressing Escape equivalent to clicking the relevant button.
.PP
If \fIparent\fR is 0, the message box becomes an application-global modal dialog box. If \fIparent\fR is a widget, the message box becomes modal relative to \fIparent\fR.
.PP
Note: If you do not specify an Escape button then if the Escape button is pressed then -1 will be returned. It is suggested that you specify an Escape button to prevent this from happening.
.PP
See also information(), question(), and critical().
.SS "Property Documentation"
.SH "Icon icon"
This property holds the message box's icon.
.PP
The icon of the message box can be one of the following predefined icons:
.TP
QMessageBox::NoIcon
.TP
QMessageBox::Question
.TP
QMessageBox::Information
.TP
QMessageBox::Warning
.TP
QMessageBox::Critical
.PP
The actual pixmap used for displaying the icon depends on the current GUI style. You can also set a custom pixmap icon using the QMessageBox::iconPixmap property. The default icon is QMessageBox::NoIcon.
.PP
See also iconPixmap.
.PP
Set this property's value with setIcon() and get this property's value with icon().
.SH "QPixmap iconPixmap"
This property holds the current icon.
.PP
The icon currently used by the message box. Note that it's often hard to draw one pixmap that looks appropriate in both Motif and Windows GUI styles; you may want to draw two pixmaps.
.PP
See also icon.
.PP
Set this property's value with setIconPixmap() and get this property's value with iconPixmap().
This property holds the message box text to be displayed.
.PP
The text will be interpreted either as a plain text or as rich text, depending on the text format setting (QMessageBox::textFormat). The default setting is AutoText, i.e. the message box will try to auto-detect the format of the text.