QMessageBox 類

The QMessageBox 類提供用於告知用戶或嚮用戶詢問問題並接收答案的模態對話框。 更多...

頭: #include <QMessageBox>
qmake: QT += widgets
繼承: QDialog

公共類型

enum ButtonRole { InvalidRole, AcceptRole, RejectRole, DestructiveRole, ..., NRoles }
enum Icon { NoIcon, Question, Information, Warning, Critical }
enum StandardButton { Ok, Open, Save, Cancel, ..., ButtonMask }
flags StandardButtons

特性

公共函數

QMessageBox (QWidget * parent = nullptr)
QMessageBox (QMessageBox::Icon icon , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = NoButton, QWidget * parent = nullptr, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint)
virtual ~QMessageBox ()
void addButton (QAbstractButton * button , QMessageBox::ButtonRole role )
QPushButton * addButton (const QString & text , QMessageBox::ButtonRole role )
QPushButton * addButton (QMessageBox::StandardButton button )
QAbstractButton * button (QMessageBox::StandardButton which ) const
QMessageBox::ButtonRole buttonRole (QAbstractButton * button ) const
QList<QAbstractButton *> buttons () const
QCheckBox * checkBox () const
QAbstractButton * clickedButton () const
QPushButton * defaultButton () const
QString detailedText () const
QAbstractButton * escapeButton () const
QMessageBox::Icon 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 (QMessageBox::StandardButton button )
void setDetailedText (const QString & text )
void setEscapeButton (QAbstractButton * button )
void setEscapeButton (QMessageBox::StandardButton button )
void setIcon ( QMessageBox::Icon )
void setIconPixmap (const QPixmap & pixmap )
void setInformativeText (const QString & text )
void setStandardButtons (QMessageBox::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 )
QMessageBox::StandardButton standardButton (QAbstractButton * button ) const
QMessageBox::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())
QMessageBox::StandardButton critical (QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)
int critical (QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButton button0 , QMessageBox::StandardButton button1 )
QMessageBox::StandardButton information (QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)
QMessageBox::StandardButton information (QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButton button0 , QMessageBox::StandardButton button1 = NoButton)
QMessageBox::StandardButton question (QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = StandardButtons(Yes | No), QMessageBox::StandardButton defaultButton = NoButton)
int question (QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButton button0 , QMessageBox::StandardButton button1 )
const QMetaObject staticMetaObject
QMessageBox::StandardButton warning (QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)
int warning (QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButton button0 , QMessageBox::StandardButton button1 )

重實現保護函數

virtual void changeEvent (QEvent * ev ) override
virtual void closeEvent (QCloseEvent * e ) override
virtual bool event (QEvent * e ) override
virtual void keyPressEvent (QKeyEvent * e ) override
virtual void resizeEvent (QResizeEvent * event ) override
virtual void showEvent (QShowEvent * e ) override

額外繼承成員

詳細描述

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.

基於特性的 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 消息文本 特性。

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.

靜態函數 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 情報文本 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
}
					
					

默認鍵和 Esc 鍵

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. 若有 Cancel button, it is the button activated when Esc is pressed.
  3. If there is exactly one button having either the Reject role 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 不起作用。

另請參閱 QDialogButtonBox , GUI Design Handbook: Message Box , 標準對話框範例 ,和 應用程序範例 .

成員類型文檔編製

enum QMessageBox:: Icon

此枚舉擁有下列值:

常量 描述
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.

enum QMessageBox:: StandardButton
flags QMessageBox:: StandardButtons

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 .

特性文檔編製

detailedText : QString

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 .

icon : Icon

此特性保持消息框的圖標

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 特性。

訪問函數:

QMessageBox::Icon icon () const
void setIcon ( QMessageBox::Icon )

另請參閱 iconPixmap .

iconPixmap : QPixmap

此特性保持當前圖標

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 .

informativeText : QString

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 .

standardButtons : StandardButtons

消息框中的標準按鈕集閤

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

默認情況下,此特性不包含標準按鈕。

該特性在 Qt 4.2 引入。

訪問函數:

QMessageBox::StandardButtons standardButtons () const
void setStandardButtons (QMessageBox::StandardButtons buttons )

另請參閱 addButton ().

text : QString

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 .

textFormat : Qt::TextFormat

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

The current text format used by the message box. See the Qt::TextFormat 枚舉瞭解可能選項的解釋。

默認格式為 Qt::AutoText .

訪問函數:

Qt::TextFormat textFormat () const
void setTextFormat (Qt::TextFormat format )

另請參閱 setText ().

textInteractionFlags : Qt::TextInteractionFlags

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 .

成員函數文檔編製

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.

常量 描述
InvalidRole 按鈕無效。
AcceptRole Clicking the button causes the dialog to be accepted (e.g. OK).
RejectRole Clicking the button causes the dialog to be rejected (e.g. Cancel).
DestructiveRole Clicking the button causes a destructive change (e.g. for Discarding Changes) and closes the dialog.
ActionRole 點擊按鈕導緻對話框中元素改變。
HelpRole 可以點擊按鈕以請求幫助。
YesRole 像 Yes 按鈕的按鈕。
NoRole The button is a "No"-like button.
ApplyRole The button applies current changes.
ResetRole The button resets the dialog's fields to default values.

另請參閱 StandardButton .

QMessageBox:: QMessageBox ( QWidget * parent = nullptr)

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.

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

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 構造函數。

消息框是 應用程序模態 對話框。

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

[虛擬] QMessageBox:: ~QMessageBox ()

銷毀消息框。

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

  1. It prefers parent->icon() if that exists.
  2. If not, it tries the top-level widget containing parent .
  3. If that fails, it tries the active window.
  4. As a last resort it uses the Information icon.

The about box has a single button labelled "OK". On 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 ().

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

添加給定 button 到消息框采用指定 role .

該函數在 Qt 4.2 引入。

另請參閱 removeButton (), button (),和 setStandardButtons ().

QPushButton *QMessageBox:: addButton (const QString & text , QMessageBox::ButtonRole role )

這是重載函數。

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

該函數在 Qt 4.2 引入。

QPushButton *QMessageBox:: addButton ( QMessageBox::StandardButton button )

這是重載函數。

添加標準 button to the message box if it is valid to do so, and returns the push button.

該函數在 Qt 4.2 引入。

另請參閱 setStandardButtons ().

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

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

該函數在 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 .

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

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

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

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

該函數在 Qt 4.5 引入。

另請參閱 buttonRole (), addButton (),和 removeButton ().

[override virtual protected] void QMessageBox:: changeEvent ( QEvent * ev )

重實現自 QWidget::changeEvent ().

QCheckBox *QMessageBox:: checkBox () const

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

該函數在 Qt 5.2 引入。

另請參閱 setCheckBox ().

QAbstractButton *QMessageBox:: clickedButton () const

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

exec () 尚未被調用,返迴 nullptr。

範例:

QMessageBox messageBox(this);
QAbstractButton *disconnectButton =
      messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole);
...
messageBox.exec();
if (messageBox.clickedButton() == disconnectButton) {
    ...
}
					

該函數在 Qt 4.2 引入。

另請參閱 standardButton () 和 button ().

[override virtual protected] void QMessageBox:: closeEvent ( QCloseEvent * e )

重實現自 QDialog::closeEvent ().

[static] QMessageBox::StandardButton QMessageBox:: critical ( QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = Ok, QMessageBox::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 ().

QPushButton *QMessageBox:: defaultButton () const

Returns the button that should be the message box's 默認按鈕 。返迴 nullptr 若未設置默認按鈕。

該函數在 Qt 4.2 引入。

另請參閱 setDefaultButton (), addButton (),和 QPushButton::setDefault ().

QAbstractButton *QMessageBox:: escapeButton () const

返迴被激活按鈕,當按下 Esc 鍵時。

默認情況下, QMessageBox attempts to automatically detect an escape button as follows:

  1. If there is only one button, it is made the escape button.
  2. 若有 Cancel button, it is made the escape button.
  3. On macOS only, if there is exactly one button with the role QMessageBox::RejectRole , it is made the escape button.

When an escape button could not be automatically detected, pressing Esc 不起作用。

該函數在 Qt 4.2 引入。

另請參閱 setEscapeButton () 和 addButton ().

[override virtual protected] bool QMessageBox:: event ( QEvent * e )

重實現自 QWidget::event ().

[virtual slot] int QMessageBox:: exec ()

重實現自 QDialog::exec ().

展示消息框作為 模態對話框 ,阻塞直到用戶關閉它。

當使用 QMessageBox with standard buttons, this function 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.

另請參閱 show () 和 result ().

[static] QMessageBox::StandardButton QMessageBox:: information ( QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = Ok, QMessageBox::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 ().

[override virtual protected] void QMessageBox:: keyPressEvent ( QKeyEvent * e )

重實現自 QDialog::keyPressEvent ().

void QMessageBox:: open ( QObject * receiver , const char * member )

打開對話框並連接其 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] QMessageBox::StandardButton QMessageBox:: question ( QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = StandardButtons(Yes | No), QMessageBox::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 ().

void QMessageBox:: removeButton ( QAbstractButton * button )

移除 button 從按鈕框但不刪除它。

該函數在 Qt 4.2 引入。

另請參閱 addButton () 和 setStandardButtons ().

[override virtual protected] void QMessageBox:: resizeEvent ( QResizeEvent * event )

重實現自 QDialog::resizeEvent ().

void QMessageBox:: setCheckBox ( QCheckBox * cb )

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

void QMessageBox:: setDefaultButton ( QPushButton * button )

設置消息框的 默認按鈕 to button .

該函數在 Qt 4.2 引入。

另請參閱 defaultButton (), addButton (),和 QPushButton::setDefault ().

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

設置消息框的 默認按鈕 to button .

該函數在 Qt 4.3 引入。

另請參閱 addButton () 和 QPushButton::setDefault ().

void QMessageBox:: setEscapeButton ( QAbstractButton * button )

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

該函數在 Qt 4.2 引入。

另請參閱 escapeButton (), addButton (),和 clickedButton ().

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

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

該函數在 Qt 4.3 引入。

另請參閱 addButton () 和 clickedButton ().

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

此函數投影 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 引入。

void QMessageBox:: setWindowTitle (const QString & title )

此函數投影 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 引入。

[override virtual protected] void QMessageBox:: showEvent ( QShowEvent * e )

重實現自 QDialog::showEvent ().

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

返迴的標準按鈕枚舉值對應給定 button ,或 NoButton 若給定 button 不是標準按鈕。

該函數在 Qt 4.2 引入。

另請參閱 button () 和 standardButtons ().

[static] QMessageBox::StandardButton QMessageBox:: warning ( QWidget * parent , const QString & title , const QString & text , QMessageBox::StandardButtons buttons = Ok, QMessageBox::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 ().