The QMessageBox 類提供用於告知用戶或嚮用戶詢問問題並接收答案的模態對話框。 更多...
| 頭: | #include <QMessageBox> |
| qmake: | QT += widgets |
| 繼承: | QDialog |
| enum | ButtonRole { InvalidRole, AcceptRole, RejectRole, DestructiveRole, ..., ResetRole } |
| enum | Icon { NoIcon, Question, Information, Warning, Critical } |
| enum | StandardButton { Ok, Open, Save, Cancel, ..., ButtonMask } |
| flags | StandardButtons |
|
|
| QMessageBox (QWidget * parent = Q_NULLPTR) | |
| QMessageBox (Icon icon , const QString & title , const QString & text , StandardButtons buttons = NoButton, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint) | |
| ~QMessageBox () | |
| void | addButton (QAbstractButton * button , ButtonRole role ) |
| QPushButton * | addButton (const QString & text , ButtonRole role ) |
| QPushButton * | addButton (StandardButton button ) |
| QAbstractButton * | button (StandardButton which ) const |
| ButtonRole | buttonRole (QAbstractButton * button ) const |
| QList<QAbstractButton *> | buttons () const |
| QCheckBox * | checkBox () const |
| QAbstractButton * | clickedButton () const |
| QPushButton * | defaultButton () const |
| QString | detailedText () const |
| QAbstractButton * | escapeButton () const |
| 圖標 | icon () const |
| QPixmap | iconPixmap () const |
| QString | informativeText () const |
| void | open (QObject * receiver , const char * member ) |
| void | removeButton (QAbstractButton * button ) |
| void | setCheckBox (QCheckBox * cb ) |
| void | setDefaultButton (QPushButton * button ) |
| void | setDefaultButton (StandardButton button ) |
| void | setDetailedText (const QString & text ) |
| void | setEscapeButton (QAbstractButton * button ) |
| void | setEscapeButton (StandardButton button ) |
| void | setIcon ( 圖標 ) |
| void | setIconPixmap (const QPixmap & pixmap ) |
| void | setInformativeText (const QString & text ) |
| void | setStandardButtons (StandardButtons buttons ) |
| void | setText (const QString & text ) |
| void | setTextFormat (Qt::TextFormat format ) |
| void | setTextInteractionFlags (Qt::TextInteractionFlags flags ) |
| void | setWindowModality (Qt::WindowModality windowModality ) |
| void | setWindowTitle (const QString & title ) |
| StandardButton | standardButton (QAbstractButton * button ) const |
| StandardButtons | standardButtons () const |
| QString | text () const |
| Qt::TextFormat | textFormat () const |
| Qt::TextInteractionFlags | textInteractionFlags () const |
| virtual int | exec () |
| void | buttonClicked (QAbstractButton * button ) |
| void | about (QWidget * parent , const QString & title , const QString & text ) |
| void | aboutQt (QWidget * parent , const QString & title = QString()) |
| StandardButton | critical (QWidget * parent , const QString & title , const QString & text , StandardButtons buttons = Ok, StandardButton defaultButton = NoButton) |
| StandardButton | information (QWidget * parent , const QString & title , const QString & text , StandardButtons buttons = Ok, StandardButton defaultButton = NoButton) |
| StandardButton | question (QWidget * parent , const QString & title , const QString & text , StandardButtons buttons = StandardButtons( Yes | No ), StandardButton defaultButton = NoButton) |
| StandardButton | warning (QWidget * parent , const QString & title , const QString & text , StandardButtons buttons = Ok, StandardButton defaultButton = NoButton) |
| virtual void | changeEvent (QEvent * ev ) |
| virtual void | closeEvent (QCloseEvent * e ) |
| virtual bool | event (QEvent * e ) |
| virtual void | keyPressEvent (QKeyEvent * e ) |
| virtual void | resizeEvent (QResizeEvent * event ) |
| virtual void | showEvent (QShowEvent * e ) |
The QMessageBox 類提供用於告知用戶或嚮用戶詢問問題並接收答案的模態對話框。
消息框顯示首要 text 以嚮用戶發齣狀況警報, 情報文本 以進一步闡述警報 (或嚮用戶詢問問題),和可選 細節文本 以提供更多數據,若用戶要求。消息框也可以顯示 icon and 標準按鈕 為接受用戶響應。
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.
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 消息文本 特性。
QMessageBox msgBox; msgBox.setText("The document has been modified."); msgBox.exec();
用戶必須點擊 OK button to dismiss the message box. The rest of the GUI is blocked until the message box is dismissed.
A better approach than just alerting the user to an event is to also ask the user what to do about it. Store the question in the 情報文本 property, and set the 標準按鈕 property to the set of buttons you want as the set of user responses. The buttons are specified by combining values from StandardButtons using the bitwise OR operator. The display order for the buttons is platform-dependent. For example, on Windows, Save is displayed to the left of Cancel , whereas on Mac OS, the order is reversed.
Mark one of your standard buttons to be your 默認按鈕 .
QMessageBox msgBox; msgBox.setText("The document has been modified."); msgBox.setInformativeText("Do you want to save your changes?"); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Save); int ret = msgBox.exec();
This is the approach recommended in the macOS Guidelines . Similar guidelines apply for the other platforms, but note the different ways the 情報文本 is handled for different platforms.
The exec () 槽返迴 StandardButtons value of the button that was clicked.
switch (ret) { case QMessageBox::Save: // Save was clicked break; case QMessageBox::Discard: // Don't Save was clicked break; case QMessageBox::Cancel: // Cancel was clicked break; default: // should never be reached break; }
To give the user more information to help him answer the question, set the 細節文本 特性。若 細節文本 property is set, the Show Details... button will be shown.
點擊 Show Details... button displays the detailed text.
The 細節文本 property is always interpreted as plain text. The main text and 情報文本 properties can be either plain text or rich text. These strings are interpreted according to the setting of the 文本格式 property. The default setting is auto-text .
Note that for some plain text strings containing XML meta-characters, the auto-text rich text detection test may fail causing your plain text string to be interpreted incorrectly as rich text. In these rare cases, use Qt::convertFromPlainText () to convert your plain text string to a visually equivalent rich text string, or set the 文本格式 property explicitly with setTextFormat ().
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 預定義圖標 . The following rules are guidelines:
|
詢問 | For asking a question during normal operations. |
|
信息 | For reporting information about normal operations. |
|
警告 | For reporting non-critical errors. |
|
危急 | For reporting critical errors. |
預定義圖標 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 特性。
In summary, to set an icon, use either setIcon () for one of the standard icons, or setIconPixmap () for a custom icon.
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
情報文本
and
細節文本
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
應用程序名稱
作為
窗口標題
, which means that if you have an informative text in addition to your main text, you must concatenate it to the
text
參數。
Note that the static function signatures have changed with respect to their button parameters, which are now used to set the 標準按鈕 和 默認按鈕 .
Static functions are available for creating information (), question (), warning (),和 critical () message boxes.
int ret = QMessageBox::warning(this, tr("My Application"), tr("The document has been modified.\n" "Do you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
The 標準對話框 範例展示如何使用 QMessageBox and the other built-in Qt dialogs.
若 標準按鈕 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 用於 QMessageBox to determine the ordering of the buttons on screen (which varies according to the platform). You can test the value of clickedButton () after calling exec (). For example,
QMessageBox msgBox; QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole); QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort); msgBox.exec(); if (msgBox.clickedButton() == connectButton) { // connect } else if (msgBox.clickedButton() == abortButton) { // abort }
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:
When an escape button can't be determined using these rules, pressing Esc 不起作用。
另請參閱 QDialogButtonBox , GUI Design Handbook: Message Box , 標準對話框範例 ,和 應用程序範例 .
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.
| 常量 | 值 | 描述 |
|---|---|---|
QMessageBox::InvalidRole
|
-1
|
按鈕無效。 |
QMessageBox::AcceptRole
|
0
|
Clicking the button causes the dialog to be accepted (e.g. OK). |
QMessageBox::RejectRole
|
1
|
Clicking the button causes the dialog to be rejected (e.g. Cancel). |
QMessageBox::DestructiveRole
|
2
|
Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog. |
QMessageBox::ActionRole
|
3
|
點擊按鈕導緻對話框中元素改變。 |
QMessageBox::HelpRole
|
4
|
可以點擊按鈕以請求幫助。 |
QMessageBox::YesRole
|
5
|
像 Yes 按鈕的按鈕。 |
QMessageBox::NoRole
|
6
|
The button is a "No"-like button. |
QMessageBox::ApplyRole
|
8
|
The button applies current changes. |
QMessageBox::ResetRole
|
7
|
The button resets the dialog's fields to default values. |
另請參閱 StandardButton .
此枚舉擁有下列值:
| 常量 | 值 | 描述 |
|---|---|---|
QMessageBox::NoIcon
|
0
|
the message box does not have any icon. |
QMessageBox::Question
|
4
|
an icon indicating that the message is asking a question. |
QMessageBox::Information
|
1
|
an icon indicating that the message is nothing out of the ordinary. |
QMessageBox::Warning
|
2
|
an icon indicating that the message is a warning, but can be dealt with. |
QMessageBox::Critical
|
3
|
an icon indicating that the message represents a critical problem. |
These enums describe flags for standard buttons. Each button has a defined ButtonRole .
| 常量 | 值 | 描述 |
|---|---|---|
QMessageBox::Ok
|
0x00000400
|
An "OK" button defined with the AcceptRole . |
QMessageBox::Open
|
0x00002000
|
An "Open" button defined with the AcceptRole . |
QMessageBox::Save
|
0x00000800
|
A "Save" button defined with the AcceptRole . |
QMessageBox::Cancel
|
0x00400000
|
A "Cancel" button defined with the RejectRole . |
QMessageBox::Close
|
0x00200000
|
A "Close" button defined with the RejectRole . |
QMessageBox::Discard
|
0x00800000
|
A "Discard" or "Don't Save" button, depending on the platform, defined with the DestructiveRole . |
QMessageBox::Apply
|
0x02000000
|
An "Apply" button defined with the ApplyRole . |
QMessageBox::Reset
|
0x04000000
|
A "Reset" button defined with the ResetRole . |
QMessageBox::RestoreDefaults
|
0x08000000
|
A "Restore Defaults" button defined with the ResetRole . |
QMessageBox::Help
|
0x01000000
|
A "Help" button defined with the HelpRole . |
QMessageBox::SaveAll
|
0x00001000
|
A "Save All" button defined with the AcceptRole . |
QMessageBox::Yes
|
0x00004000
|
A "Yes" button defined with the YesRole . |
QMessageBox::YesToAll
|
0x00008000
|
A "Yes to All" button defined with the YesRole . |
QMessageBox::No
|
0x00010000
|
A "No" button defined with the NoRole . |
QMessageBox::NoToAll
|
0x00020000
|
A "No to All" button defined with the NoRole . |
QMessageBox::Abort
|
0x00040000
|
An "Abort" button defined with the RejectRole . |
QMessageBox::Retry
|
0x00080000
|
A "Retry" button defined with the AcceptRole . |
QMessageBox::Ignore
|
0x00100000
|
An "Ignore" button defined with the AcceptRole . |
QMessageBox::NoButton
|
0x00000000
|
無效按鈕。 |
以下值已過時:
| 常量 | 值 | 描述 |
|---|---|---|
QMessageBox::YesAll
|
YesToAll
|
使用 YesToAll 代替。 |
QMessageBox::NoAll
|
NoToAll
|
使用 NoToAll 代替。 |
QMessageBox::Default
|
0x00000100
|
使用
defaultButton
argument of
information
(),
warning
(), etc. instead, or call
setDefaultButton
().
|
QMessageBox::Escape
|
0x00000200
|
調用 setEscapeButton () 代替。 |
QMessageBox::FlagMask
|
0x00000300
|
|
QMessageBox::ButtonMask
|
~FlagMask
|
該枚舉在 Qt 4.2 引入或被修改。
StandardButtons 類型是 typedef 對於 QFlags <StandardButton>. It stores an OR combination of StandardButton values.
另請參閱 ButtonRole and standardButtons .
This property holds the text to be displayed in the details area.
The text will be interpreted as a plain text.
默認情況下,此特性包含空字符串。
該特性在 Qt 4.2 引入。
訪問函數:
| QString | detailedText () const |
| void | setDetailedText (const QString & text ) |
另請參閱 QMessageBox::text and QMessageBox::informativeText .
此特性保持消息框的圖標
The icon of the message box can be specified with one of the values:
默認為 QMessageBox::NoIcon .
The pixmap used to display the actual icon depends on the current GUI style . You can also set a custom pixmap for the icon by setting the icon pixmap 特性。
訪問函數:
| 圖標 | icon () const |
| void | setIcon ( 圖標 ) |
另請參閱 iconPixmap .
此特性保持當前圖標
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.
訪問函數:
| QPixmap | iconPixmap () const |
| void | setIconPixmap (const QPixmap & pixmap ) |
另請參閱 icon .
This property holds the informative text that provides a fuller description for the message
Infromative text can be used to expand upon the text () to give more information to the user. On the Mac, this text appears in small system font below the text (). On other platforms, it is simply appended to the existing text.
默認情況下,此特性包含空字符串。
該特性在 Qt 4.2 引入。
訪問函數:
| QString | informativeText () const |
| void | setInformativeText (const QString & text ) |
另請參閱 QMessageBox::text and QMessageBox::detailedText .
消息框中的標準按鈕集閤
This property controls which standard buttons are used by the message box.
默認情況下,此特性不包含標準按鈕。
該特性在 Qt 4.2 引入。
訪問函數:
| StandardButtons | standardButtons () const |
| void | setStandardButtons (StandardButtons buttons ) |
另請參閱 addButton ().
This property holds the message box text to be displayed.
The text will be interpreted either as a plain text or as rich text, depending on the text format setting ( QMessageBox::textFormat ). The default setting is 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.
訪問函數:
| QString | text () const |
| void | setText (const QString & text ) |
另請參閱 textFormat , QMessageBox::informativeText ,和 QMessageBox::detailedText .
This property holds the format of the text displayed by the message box
The current text format used by the message box. See the Qt::TextFormat 枚舉瞭解可能選項的解釋。
默認格式為 Qt::AutoText .
訪問函數:
| Qt::TextFormat | textFormat () const |
| void | setTextFormat (Qt::TextFormat format ) |
另請參閱 setText ().
Specifies how the label of the message box should interact with user input.
默認值取決於樣式。
該特性在 Qt 5.1 引入。
訪問函數:
| Qt::TextInteractionFlags | textInteractionFlags () const |
| void | setTextInteractionFlags (Qt::TextInteractionFlags flags ) |
另請參閱 QStyle::SH_MessageBox_TextInteractionFlags .
Constructs a message box with no text and no buttons. parent 被傳遞給 QDialog 構造函數。
On macOS, if you want your message box to appear as a Qt::Sheet of its parent , set the message box's window modality to Qt::WindowModal or use open (). Otherwise, the message box will be a standard dialog.
Constructs a message box with the given icon , title , text , and standard buttons . Standard or custom buttons can be added at any time using addButton ()。 parent and f 自變量被傳遞給 QDialog 構造函數。
消息框是 應用程序模態 對話框。
在 macOS,若 parent is not 0 and you want your message box to appear as a Qt::Sheet of that parent, set the message box's window modality to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog.
另請參閱 setWindowTitle (), setText (), setIcon (),和 setStandardButtons ().
銷毀消息框。
[static]
void
QMessageBox::
about
(
QWidget
*
parent
, const
QString
&
title
, const
QString
&
text
)
Displays a simple about box with title title 和文本 text . The about box's parent is parent .
about() looks for a suitable icon in four locations:
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.
另請參閱 QWidget::windowIcon () 和 QApplication::activeWindow ().
[static]
void
QMessageBox::
aboutQt
(
QWidget
*
parent
, const
QString
&
title
= QString())
Displays a simple message box about Qt, with the given title and centered over parent (if parent is not 0). The message includes the version number of Qt being used by the application.
這很有用,對於包括 幫助 菜單的應用程序,如展示在 菜單 範例。
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.
另請參閱 QApplication::aboutQt ().
添加給定 button 到消息框采用指定 role .
該函數在 Qt 4.2 引入。
另請參閱 removeButton (), button (),和 setStandardButtons ().
這是重載函數。
Creates a button with the given text , adds it to the message box for the specified role , and returns it.
該函數在 Qt 4.2 引入。
這是重載函數。
添加標準 button to the message box if it is valid to do so, and returns the push button.
該函數在 Qt 4.2 引入。
另請參閱 setStandardButtons ().
Returns a pointer corresponding to the standard button which , or 0 if the standard button doesn't exist in this message box.
該函數在 Qt 4.2 引入。
另請參閱 standardButtons and standardButton ().
[signal]
void
QMessageBox::
buttonClicked
(
QAbstractButton
*
button
)
This signal is emitted whenever a button is clicked inside the QMessageBox . The button that was clicked in returned in button .
Returns the button role for the specified button 。此函數返迴 InvalidRole if button is 0 or has not been added to the message box.
該函數在 Qt 4.5 引入。
另請參閱 buttons () 和 addButton ().
Returns a list of all the buttons that have been added to the message box.
該函數在 Qt 4.5 引入。
另請參閱 buttonRole (), addButton (),和 removeButton ().
[virtual protected]
void
QMessageBox::
changeEvent
(
QEvent
*
ev
)
重實現自 QWidget::changeEvent ().
Returns the checkbox shown on the dialog. This is 0 if no checkbox is set.
該函數在 Qt 5.2 引入。
另請參閱 setCheckBox ().
Returns the button that was clicked by the user, or 0 if the user hit the Esc key and no Esc 按鈕 was set.
若 exec () hasn't been called yet, returns 0.
範例:
QMessageBox messageBox(this); QAbstractButton *disconnectButton = messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole); ... messageBox.exec(); if (messageBox.clickedButton() == disconnectButton) { ... }
該函數在 Qt 4.2 引入。
另請參閱 standardButton () 和 button ().
[virtual protected]
void
QMessageBox::
closeEvent
(
QCloseEvent
*
e
)
重實現自 QWidget::closeEvent ().
[static]
StandardButton
QMessageBox::
critical
(
QWidget
*
parent
, const
QString
&
title
, const
QString
&
text
,
StandardButtons
buttons
= Ok,
StandardButton
defaultButton
= NoButton)
Opens a critical message box with the given title and text in front of the specified parent 小部件。
標準 buttons 被添加到消息框。 defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons 。若 defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.
Returns the identity of the standard button that was clicked. If Esc was pressed instead, the Esc 按鈕 被返迴。
消息框是 應用程序模態 對話框。
警告: 不要刪除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QMessageBox 構造函數。
該函數在 Qt 4.2 引入。
另請參閱 question (), warning (),和 information ().
Returns the button that should be the message box's 默認按鈕 . Returns 0 if no default button was set.
該函數在 Qt 4.2 引入。
另請參閱 setDefaultButton (), addButton (),和 QPushButton::setDefault ().
返迴被激活按鈕,當按下 Esc 鍵時。
默認情況下, QMessageBox attempts to automatically detect an escape button as follows:
When an escape button could not be automatically detected, pressing Esc 不起作用。
該函數在 Qt 4.2 引入。
另請參閱 setEscapeButton () 和 addButton ().
[virtual protected]
bool
QMessageBox::
event
(
QEvent
*
e
)
重實現自 QObject::event ().
[virtual slot]
int
QMessageBox::
exec
()
重實現自 QDialog::exec ().
展示消息框作為 模態對話框 ,阻塞直到用戶關閉它。
當使用 QMessageBox with standard buttons, this functions returns a StandardButton value indicating the standard button that was clicked. When using QMessageBox with custom buttons, this function returns an opaque value; use clickedButton () to determine which button was clicked.
注意: The result () function returns also StandardButton value instead of QDialog::DialogCode .
Users cannot interact with any other window in the same application until they close the dialog, either by clicking a button or by using a mechanism provided by the window system.
[static]
StandardButton
QMessageBox::
information
(
QWidget
*
parent
, const
QString
&
title
, const
QString
&
text
,
StandardButtons
buttons
= Ok,
StandardButton
defaultButton
= NoButton)
打開信息消息框采用給定 title and text in front of the specified parent 小部件。
標準 buttons 被添加到消息框。 defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons 。若 defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.
Returns the identity of the standard button that was clicked. If Esc was pressed instead, the Esc 按鈕 被返迴。
消息框是 應用程序模態 對話框。
警告: 不要刪除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QMessageBox 構造函數。
該函數在 Qt 4.2 引入。
另請參閱 question (), warning (),和 critical ().
[virtual protected]
void
QMessageBox::
keyPressEvent
(
QKeyEvent
*
e
)
重實現自 QWidget::keyPressEvent ().
這是重載函數。
打開對話框並連接其 finished () 或 buttonClicked () 信號到槽,指定通過 receiver and member 。若槽在 member has a pointer for its first parameter the connection is to buttonClicked (), otherwise the connection is to finished ().
將從槽斷開信號連接,當關閉對話框時。
[static]
StandardButton
QMessageBox::
question
(
QWidget
*
parent
, const
QString
&
title
, const
QString
&
text
,
StandardButtons
buttons
= StandardButtons( Yes | No ),
StandardButton
defaultButton
= NoButton)
打開問題消息框采用給定 title and text in front of the specified parent 小部件。
標準 buttons 被添加到消息框。 defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons 。若 defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.
Returns the identity of the standard button that was clicked. If Esc was pressed instead, the Esc 按鈕 被返迴。
消息框是 應用程序模態 對話框。
警告: 不要刪除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QMessageBox 構造函數。
該函數在 Qt 4.2 引入。
另請參閱 information (), warning (),和 critical ().
移除 button 從按鈕框但不刪除它。
該函數在 Qt 4.2 引入。
另請參閱 addButton () 和 setStandardButtons ().
[virtual protected]
void
QMessageBox::
resizeEvent
(
QResizeEvent
*
event
)
重實現自 QWidget::resizeEvent ().
Sets the checkbox cb on the message dialog. The message box takes ownership of the checkbox. The argument cb can be 0 to remove an existing checkbox from the message box.
該函數在 Qt 5.2 引入。
另請參閱 checkBox ().
設置消息框的 默認按鈕 to button .
該函數在 Qt 4.2 引入。
另請參閱 defaultButton (), addButton (),和 QPushButton::setDefault ().
設置消息框的 默認按鈕 to button .
該函數在 Qt 4.3 引入。
另請參閱 addButton () 和 QPushButton::setDefault ().
Sets the button that gets activated when the Escape key is pressed to button .
該函數在 Qt 4.2 引入。
另請參閱 escapeButton (), addButton (),和 clickedButton ().
Sets the buttons that gets activated when the Escape key is pressed to button .
該函數在 Qt 4.3 引入。
另請參閱 addButton () 和 clickedButton ().
此函數投影 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 ,否則消息框將是標準對話框。
該函數在 Qt 4.2 引入。
此函數投影 QWidget::setWindowTitle ().
Sets the title of the message box to title . On macOS, the window title is ignored (as required by the macOS Guidelines).
該函數在 Qt 4.2 引入。
[virtual protected]
void
QMessageBox::
showEvent
(
QShowEvent
*
e
)
重實現自 QWidget::showEvent ().
返迴的標準按鈕枚舉值對應給定 button ,或 NoButton 若給定 button 不是標準按鈕。
該函數在 Qt 4.2 引入。
另請參閱 button () 和 standardButtons ().
[static]
StandardButton
QMessageBox::
warning
(
QWidget
*
parent
, const
QString
&
title
, const
QString
&
text
,
StandardButtons
buttons
= Ok,
StandardButton
defaultButton
= NoButton)
Opens a warning message box with the given title and text in front of the specified parent 小部件。
標準 buttons 被添加到消息框。 defaultButton specifies the button used when Enter is pressed. defaultButton must refer to a button that was given in buttons 。若 defaultButton is QMessageBox::NoButton , QMessageBox chooses a suitable default automatically.
Returns the identity of the standard button that was clicked. If Esc was pressed instead, the Esc 按鈕 被返迴。
消息框是 應用程序模態 對話框。
警告: 不要刪除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QMessageBox 構造函數。
該函數在 Qt 4.2 引入。
另請參閱 question (), information (),和 critical ().