QMessageBox Class

Header:#include < QMessageBox >
qmake:QT += widgets
Inherits:QDialog

Public Types

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

Properties

detailedText : QString
icon : Icon
iconPixmap : QPixmap
informativeText : QString
standardButtons : StandardButtons
text : QString
textFormat : Qt::TextFormat
textInteractionFlags : Qt::TextInteractionFlags

Public Functions

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

QMessageBox(QWidget *parent = nullptr)
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

Public Slots

virtual int exec() override

Signals

void buttonClicked(QAbstractButton *button)

Static Public Members

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)
QMessageBox::StandardButton information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)
QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = StandardButtons(Yes | No), QMessageBox::StandardButton defaultButton = NoButton)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)

Reimplemented Protected Functions

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

Detailed Description

消息框显示一个主要文本,用于提醒用户注意某种情况;一个信息文本,用于进一步解释警报或向用户询问问题;一个可选的详细文本,用于在用户请求时提供更多数据。消息框还可以显示用于接受用户响应的图标和标准按钮。
提供了两个用于使用QMessageBox的API,基于属性的API和静态函数。调用其中一个静态函数是更简单的方法,但它不如使用基于属性的API灵活,而且结果的信息量也更少。建议使用基于属性的API。

The Property-based API

要使用基于属性的API,请构造QMessageBox的实例,设置所需的属性,并调用exec()来显示消息。最简单的配置是只设置消息文本属性。

  QMessageBox msgBox;
  msgBox.setText("The document has been modified.");
  msgBox.exec();

用户必须单击OK按钮以关闭消息框。GUI的其余部分将被阻塞,直到消息框被解除。
在这里插入图片描述
比仅仅提醒用户事件更好的方法是同时询问用户该如何处理该事件。将问题存储在信息文本属性中,并将标准按钮属性设置为希望作为用户响应集的按钮集。按钮是通过使用按位或操作符组合StandardButtons中的值来指定的。按钮的显示顺序取决于平台。例如,在Windows上,“保存”显示在“取消”的左侧,而在Mac OS上,顺序相反。
将一个标准按钮标记为默认按钮。

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

这是macOS指南中推荐的方法。类似的指导方针适用于其他平台,但请注意,不同平台处理信息文本的方式不同。
在这里插入图片描述
exec()槽返回被单击按钮的StandardButtons值。

 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;
  }

为了给用户提供更多的信息来帮助他回答问题,可以设置详细文本属性。如果设置了详细文本属性,则Show Details…按钮将显示。
在这里插入图片描述
单击显示详细信息…按钮显示详细文本。
在这里插入图片描述

Rich Text and the Text Format Property

详细文本属性总是被解释为纯文本。主要文本和信息文本属性可以是纯文本或富文本。这些字符串根据文本格式属性的设置进行解释。默认设置为自动文本。
注意,对于一些包含XML元字符的纯文本字符串,自动文本富文本检测测试可能会失败,导致纯文本字符串被错误地解释为富文本。在这些罕见的情况下,使用Qt::convertFromPlainText()将纯文本字符串转换为视觉上等效的富文本字符串,或者使用setTextFormat()显式设置文本格式属性。

Severity Levels and the Icon and Pixmap Properties

QMessageBox支持四种预定义的消息严重性级别,或者消息类型,它们实际上只在各自显示的预定义图标中有所不同。通过将图标属性设置为预定义图标之一来指定四种预定义消息类型之一。以下规则是指导方针:
在这里插入图片描述
预定义图标不是由QMessageBox定义的,而是由样式提供的。默认值为“No Icon”。除此之外,所有情况下的消息框都是相同的。当使用标准图标时,请使用表格中推荐的图标,或者使用平台风格指南中推荐的图标。如果所有标准图标都不适合您的消息框,则可以通过设置图标pixmap属性而不是设置图标属性来使用自定义图标。
总而言之,要设置图标,可以使用setIcon()来设置标准图标,或者使用setIconPixmap()来设置自定义图标。

The Static Functions API

使用静态函数API构建消息框虽然方便,但不如使用基于属性的API灵活,因为静态函数签名缺乏用于设置信息文本和详细文本属性的参数。解决这个问题的一种方法是使用title参数作为消息框的主文本,并使用text参数作为消息框的信息文本。由于这有一个明显的缺点,即使消息框的可读性降低,因此平台指南不推荐这样做。Microsoft Windows用户界面指南建议使用应用程序名称作为窗口的标题,这意味着如果除了主文本之外还有一个信息文本,则必须将其连接到text参数。
注意,静态函数签名相对于它们的按钮参数已经发生了变化,这些参数现在用于设置标准按钮和默认按钮。
静态函数可用于创建information()、question()、warning()和critical()消息框。

  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);

标准对话框示例展示了如何使用QMessageBox和其他内置Qt对话框。

Advanced Usage

如果标准按钮对于您的消息框来说不够灵活,您可以使用addButton()重载,它接受一个文本和一个ButtonRole来添加自定义按钮。QMessageBox使用ButtonRole来确定屏幕上按钮的顺序(根据平台而变化)。可以在调用exec()之后测试clickedButton()的值。例如,

  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
  }

Default and Escape Keys

默认按钮(即按下Enter键时激活的按钮)可以使用setDefaultButton()指定。如果未指定默认按钮,QMessageBox将根据消息框中使用的按钮的按钮角色尝试查找一个。
可以使用setEscapeButton()指定escape按钮(按Esc键时激活的按钮)。如果没有指定转义按钮,QMessageBox将尝试使用以下规则找到一个转义按钮:

  • 如果只有一个按钮,则为按Esc时激活的按钮。
  • 如果有“取消”按钮,则是按Esc时激活的按钮。
  • 如果只有一个按钮具有Reject角色或No角色,则它是按Esc时激活的按钮。

当无法使用这些规则确定退出按钮时,按Esc无效。

See also QDialogButtonBox, GUI Design Handbook: Message Box, Standard Dialogs Example, and Application Example.

Member Type Documentation

enum QMessageBox::ButtonRole
	此enum描述可用于描述按钮框中的按钮的角色。这些角色的组合是用来描述其行为的不同方面的标志。
See also StandardButton.
ConstantValueDescription
QMessageBox::InvalidRole-1按钮无效。
QMessageBox::AcceptRole0单击按钮将导致接受对话框(例如OK)。
QMessageBox::RejectRole1单击该按钮将导致拒绝对话框(例如取消)。
QMessageBox::DestructiveRole2单击该按钮将导致破坏性更改(例如丢弃更改)并关闭对话框。
QMessageBox::ActionRole3单击该按钮将导致对对话框中的元素进行更改。
QMessageBox::HelpRole4点击这个按钮可以请求帮助。
QMessageBox::YesRole5该按钮是一个类似“Yes”的按钮。
QMessageBox::NoRole6这个按钮是一个类似“否”的按钮。
QMessageBox::ApplyRole8按钮应用当前更改。
QMessageBox::ResetRole7该按钮将对话框的字段重置为默认值。
enum QMessageBox::Icon
	This enum has the following values:
ConstantValueDescription
QMessageBox::NoIcon0消息框没有任何图标。
QMessageBox::Question4表示消息正在询问问题的图标。
QMessageBox::Information1一个图标表示该消息没有任何异常。
QMessageBox::Warning2一个图标,表示该消息是警告,但可以处理。
QMessageBox::Critical3一个图标,表示消息代表一个严重的问题。
enum QMessageBox::StandardButton
flags QMessageBox::StandardButtons
	这些枚举描述标准按钮的标志。每个按钮都有一个已定义的ButtonRole。
	这个枚举在Qt 4.2中被引入或修改。
StandardButtons类型是QFlags<StandardButton>的类型定义。它存储StandardButton值的OR组合。
See also ButtonRole and standardButtons.
ConstantValueDescription
QMessageBox::Ok0x00000400用AcceptRole定义的“OK”按钮。
QMessageBox::Open0x00002000用AcceptRole定义的“Open”按钮。
QMessageBox::Save0x00000800用AcceptRole定义的“Save”按钮。
QMessageBox::Cancel0x00400000用RejectRole定义的“Cancel”按钮。
QMessageBox::Close0x00200000用RejectRole定义的“Close”按钮。
QMessageBox::Discard0x00800000一个“丢弃”或“不保存”按钮,取决于平台,由DestructiveRole定义。
QMessageBox::Apply0x02000000用ApplyRole定义的“Apply”按钮。
QMessageBox::Reset0x04000000用ResetRole定义的Reset”按钮。
QMessageBox::RestoreDefaults0x08000000用ResetRole定义的“恢复默认值”按钮。
QMessageBox::Help0x01000000一个“Help”按钮,由HelpRole定义。
QMessageBox::SaveAll0x00001000用AcceptRole定义的“Save All”按钮。
QMessageBox::Yes0x00004000使用YesRole定义的“Yes”按钮。
QMessageBox::YesToAll0x00008000使用YesRole定义的“Yes to All”按钮。
QMessageBox::No0x00010000用NoRole定义的“No”按钮。
QMessageBox::NoToAll0x00020000用NoRole定义的“No to All”按钮。
QMessageBox::Abort0x00040000用RejectRole定义的“Abort”按钮。
QMessageBox::Retry0x00080000用AcceptRole定义的“Retry”按钮。
QMessageBox::Ignore0x00100000用AcceptRole定义的“Ignore”按钮。
QMessageBox::NoButton0x00000000无效的按钮。

The following values are obsolete:

ConstantValueDescription
QMessageBox::YesAllYesToAll使用YesToAll代替。
QMessageBox::NoAllNoToAll用NoToAll代替。
QMessageBox::Default0x00000100使用information()、warning()等的defaultButton参数代替,或者调用setDefaultButton()。
QMessageBox::Escape0x00000200而是调用setEscapeButton()。
QMessageBox::FlagMask0x00000300
QMessageBox::ButtonMask~FlagMask

Property Documentation

detailedText : QString
	此属性保存要在详细信息区域中显示的文本。
	文本将被解释为纯文本。
	默认情况下,此属性包含一个空字符串。
	这个属性是在Qt 4.2中引入的。
访问函数:
	QString detailedText() const
	void setDetailedText(const QString &text)

See also QMessageBox::text and QMessageBox::informativeText.
icon : Icon
	此属性保存消息框的图标
	消息框的图标可以用以下值之一指定:
QMessageBox::NoIcon
QMessageBox::Question
QMessageBox::Information
QMessageBox::Warning
QMessageBox::Critical
	默认为QMessageBox::NoIcon。
	用于显示实际图标的像素图取决于当前的GUI样式。您还可以通过设置图标像素图属性来设置图标的自定义像素图。
访问函数:
	QMessageBox::Icon icon() const
	void setIcon(QMessageBox::Icon)

See also iconPixmap.
iconPixmap : QPixmap
	此属性保存当前图标
	消息框当前使用的图标。请注意,通常很难画出适合所有GUI样式的像素图;您可能希望为每个平台提供不同的像素图。
	默认情况下,此属性是未定义的。
访问函数:
	QPixmap iconPixmap() const
	void setIconPixmap(const QPixmap &pixmap)

See also icon.
informativeText : QString
	此属性保存为消息提供更完整描述的信息文本
	创新文本可以用来扩展text(),向用户提供更多信息。在Mac上,该文本以小系统字体显示在text()下面。在其他平台上,它只是附加到现有文本中。
	默认情况下,此属性包含一个空字符串。
	这个属性是在Qt 4.2中引入的。
访问函数:
	QString informativeText() const
	void setInformativeText(const QString &text)

See also QMessageBox::text and QMessageBox::detailedText.
standardButtons : StandardButtons
	消息框中标准按钮的集合
	此属性控制消息框使用哪些标准按钮。
	默认情况下,此属性不包含标准按钮。
	这个属性是在Qt 4.2中引入的。
访问函数:
	QMessageBox::StandardButtons standardButtons() const
	void setStandardButtons(QMessageBox::StandardButtons buttons)

See also addButton().
text : QString
	此属性保存要显示的消息框文本。
	文本将被解释为纯文本或富文本,这取决于文本格式设置(QMessageBox::textFormat)。默认设置是Qt::AutoText,也就是说,消息框将尝试自动检测文本的格式。
	此属性的默认值是一个空字符串。
访问函数:
	QString text() const
	void setText(const QString &text)

See also textFormat, QMessageBox::informativeText, and QMessageBox::detailedText.
textFormat : Qt::TextFormat
	此属性保存消息框显示的文本格式
	消息框使用的当前文本格式。请参阅Qt::TextFormat枚举以获得可能选项的解释。
	默认格式为Qt::AutoText。
访问函数:
	Qt::TextFormat textFormat() const
	void setTextFormat(Qt::TextFormat format)

See also setText().
textInteractionFlags : Qt::TextInteractionFlags
	指定消息框的标签应如何与用户输入交互。
	默认值取决于样式。
	这个属性是在Qt 5.1中引入的。
访问函数:
	Qt::TextInteractionFlags textInteractionFlags() const
	void setTextInteractionFlags(Qt::TextInteractionFlags flags)

See also QStyle::SH_MessageBox_TextInteractionFlags.

Member Function Documentation

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)
	构造具有给定图标、标题、文本和标准按钮的消息框。可以随时使用addButton()添加标准或自定义按钮。父参数和f参数被传递给QDialog构造函数。
	消息框是一个应用程序模态对话框。
	在macOS上,如果parent不是nullptr,并且您希望消息框显示为该父窗体的Qt::Sheet,请将消息框的窗口模式设置为Qt::WindowModal(默认)。否则,消息框将是一个标准的对话框。
See also setWindowTitle(), setText(), setIcon(), and setStandardButtons().
QMessageBox::QMessageBox(QWidget *parent = nullptr)
	构造一个没有文本和按钮的消息框。parent传递给QDialog构造函数。
	在macOS上,如果你想让你的消息框显示为其父窗体的Qt::Sheet,将消息框的窗口模式设置为Qt::WindowModal或使用open()。否则,消息框将是一个标准的对话框。
[signal] void QMessageBox::buttonClicked(QAbstractButton *button)
	每当在QMessageBox中单击按钮时,就会发出此信号。点击进入的按钮返回进入按钮。
[override virtual slot] int QMessageBox::exec()
	Reimplements: QDialog::exec().
	将消息框显示为模态对话框,直到用户关闭它为止。
	当使用带有标准按钮的QMessageBox时,该函数返回一个StandardButton值,该值指示被单击的标准按钮。当使用QMessageBox和自定义按钮时,这个函数返回一个不透明的值;使用clickbutton()来确定单击了哪个按钮。
	注意:result()函数也返回StandardButton值,而不是QDialog::DialogCode。
	用户不能与同一应用程序中的任何其他窗口进行交互,除非他们通过单击按钮或使用窗口系统提供的机制关闭对话框。
See also show() and result().
[virtual] QMessageBox::~QMessageBox()
	Destroys the message box.
[static] void QMessageBox::about(QWidget *parent, const QString &title, const QString &text)
	显示一个简单的关于框,其中包含标题和文本。about框的父元素是parent。
	About()在四个位置寻找合适的图标:
	如果parent->icon()存在,它更倾向于使用它。
	如果没有,它将尝试包含parent的顶级小部件。
	如果失败,它会尝试活动窗口。
	作为最后的手段,它使用信息图标。
	about框有一个标签为“OK”的按钮。在macOS上,about框作为一个非模态窗口弹出;在其他平台上,它目前是应用程序模式。
See also QWidget::windowIcon() and QApplication::activeWindow().
[static] void QMessageBox::aboutQt(QWidget *parent, const QString &title = QString())
	显示一个关于Qt的简单消息框,带有给定的标题并居中于parent(如果parent不是nullptr)。该消息包括应用程序正在使用的Qt版本号。
	这对于包含在应用程序的Help菜单中很有用,如Menus示例所示。
	QApplication将此功能作为插槽提供。
	在macOS上,about框作为一个非模态窗口弹出;在其他平台上,它目前是应用程序模式。
See also QApplication::aboutQt().
void QMessageBox::addButton(QAbstractButton *button, QMessageBox::ButtonRole role)
	将给定按钮添加到具有指定角色的消息框中。
	这个函数是在Qt 4.2中引入的。
See also removeButton(), button(), and setStandardButtons().
QPushButton *QMessageBox::addButton(const QString &text, QMessageBox::ButtonRole role)
	这是一个重载函数。
	创建具有给定文本的按钮,将其添加到指定角色的消息框中,并返回该按钮。
	这个函数是在Qt 4.2中引入的。
QPushButton *QMessageBox::addButton(QMessageBox::StandardButton button)
	这是一个重载函数。
	在消息框中添加标准按钮(如果有效),并返回该按钮。
	这个函数是在Qt 4.2中引入的。
See also setStandardButtons().
QAbstractButton *QMessageBox::button(QMessageBox::StandardButton which) const
	返回与标准按钮对应的指针,如果此消息框中不存在标准按钮,则返回nullptr。
	这个函数是在Qt 4.2中引入的。
See also standardButtons and standardButton().
QMessageBox::ButtonRole QMessageBox::buttonRole(QAbstractButton *button) const
	返回指定按钮的按钮角色。如果按钮为nullptr或尚未添加到消息框中,则此函数返回InvalidRole。
	这个函数是在Qt 4.5中引入的。
See also buttons() and addButton().
QList<QAbstractButton *> QMessageBox::buttons() const
	返回已添加到消息框中的所有按钮的列表。
	这个函数是在Qt 4.5中引入的。
See also buttonRole(), addButton(), and removeButton().
[override virtual protected] void QMessageBox::changeEvent(QEvent *ev)
	Reimplements: QWidget::changeEvent(QEvent *event).
QCheckBox *QMessageBox::checkBox() const
	返回对话框中显示的复选框。如果没有设置复选框,则为null。
	这个函数是在Qt 5.2中引入的。
See also setCheckBox().
QAbstractButton *QMessageBox::clickedButton() const
	返回用户单击的按钮,如果用户按了Esc键并且没有设置转义按钮,则返回nullptr。
	如果exec()尚未被调用,则返回nullptr。
	例子:

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

This function was introduced in Qt 4.2.
See also standardButton() and button().
[override virtual protected] void QMessageBox::closeEvent(QCloseEvent *e)
	Reimplements: QDialog::closeEvent(QCloseEvent *e).
[static] QMessageBox::StandardButton QMessageBox::critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)
	在指定的父小部件前面打开具有给定标题和文本的关键消息框。
	标准按钮被添加到消息框中。defaultButton指定按Enter时使用的按钮。defaultButton必须引用在buttons中给定的按钮。如果defaultButton是QMessageBox::NoButton, QMessageBox会自动选择一个合适的默认值。
	返回被单击的标准按钮的标识。如果按了Esc键,则返回escape键。
	消息框是一个应用程序模态对话框。
	警告:不要在对话框执行期间删除父级。如果您想这样做,您应该使用QMessageBox构造函数之一自己创建对话框。
	这个函数是在Qt 4.2中引入的。
See also question(), warning(), and information().
QPushButton *QMessageBox::defaultButton() const
	返回应该作为消息框默认按钮的按钮。如果没有设置默认按钮,则返回nullptr。
	这个函数是在Qt 4.2中引入的。
See also setDefaultButton(), addButton(), and QPushButton::setDefault().
QAbstractButton *QMessageBox::escapeButton() const
	返回按下escape时激活的按钮。
	默认情况下,QMessageBox尝试自动检测escape按钮,如下所示:
	 1. 如果只有一个按钮,它就被称为逃生按钮。
	 2. 如果有“取消”按钮,则将其作为“退出”按钮。
	 3. 仅在macOS上,如果只有一个带有角色QMessageBox::RejectRole的按钮,则将其作为转义按钮。
	当无法自动检测到逃生按钮时,按Esc无效。
	这个函数是在Qt 4.2中引入的。
See also setEscapeButton() and addButton().
[override virtual protected] bool QMessageBox::event(QEvent *e)
	Reimplements: QWidget::event(QEvent *event).
[static] QMessageBox::StandardButton QMessageBox::information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)
	在指定的父小部件前面打开具有给定标题和文本的信息消息框。
	标准按钮被添加到消息框中。defaultButton指定按Enter时使用的按钮。defaultButton必须引用在buttons中给定的按钮。如果defaultButton是QMessageBox::NoButton, QMessageBox会自动选择一个合适的默认值。
	返回被单击的标准按钮的标识。如果按了Esc键,则返回escape键。
	消息框是一个应用程序模态对话框。
	警告:不要在对话框执行期间删除父级。如果您想这样做,您应该使用QMessageBox构造函数之一自己创建对话框。
	这个函数是在Qt 4.2中引入的。
See also question(), warning(), and critical().
[override virtual protected] void QMessageBox::keyPressEvent(QKeyEvent *e)
	Reimplements: QDialog::keyPressEvent(QKeyEvent *e).
void QMessageBox::open(QObject *receiver, const char *member)
	打开对话框并将其finished()buttonClicked()信号连接到接收器和成员指定的插槽。如果slot in成员的第一个参数有一个指针,则连接到buttonClicked(),否则连接到finished()。
	当对话框关闭时,信号将从插槽断开。
[static] QMessageBox::StandardButton QMessageBox::question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = StandardButtons(Yes | No), QMessageBox::StandardButton defaultButton = NoButton)
	在指定的父小部件前面打开一个带有给定标题和文本的问题消息框。
	标准按钮被添加到消息框中。defaultButton指定按Enter时使用的按钮。defaultButton必须引用在buttons中给定的按钮。如果defaultButton是QMessageBox::NoButton, QMessageBox会自动选择一个合适的默认值。
	返回被单击的标准按钮的标识。如果按了Esc键,则返回escape键。
	消息框是一个应用程序模态对话框。
	警告:不要在对话框执行期间删除父级。如果您想这样做,您应该使用QMessageBox构造函数之一自己创建对话框。
	这个函数是在Qt 4.2中引入的。
See also information(), warning(), and critical().
void QMessageBox::removeButton(QAbstractButton *button)
	从按钮框中移除按钮,但不删除按钮。
	这个函数是在Qt 4.2中引入的。
See also addButton() and setStandardButtons().
[override virtual protected] void QMessageBox::resizeEvent(QResizeEvent *event)
	Reimplements: QDialog::resizeEvent(QResizeEvent *).
void QMessageBox::setCheckBox(QCheckBox *cb)
	设置消息对话框上的复选框cb。消息框获得复选框的所有权。参数cb可以是nullptr,用于从消息框中删除现有的复选框。
	这个函数是在Qt 5.2中引入的。
See also checkBox().
void QMessageBox::setDefaultButton(QPushButton *button)
	将消息框的默认按钮设置为button。
	这个函数是在Qt 4.2中引入的。
See also defaultButton(), addButton(), and QPushButton::setDefault().
void QMessageBox::setDefaultButton(QMessageBox::StandardButton button)
	将消息框的默认按钮设置为button。
	这个函数是在Qt 4.3中引入的。
See also addButton() and QPushButton::setDefault().
void QMessageBox::setEscapeButton(QAbstractButton *button)
	设置当Escape键被按到按钮时激活的按钮。
	这个函数是在Qt 4.2中引入的。
See also escapeButton(), addButton(), and clickedButton().
void QMessageBox::setEscapeButton(QMessageBox::StandardButton button)
	设置当Escape键被按到按钮时激活的按钮。
	这个函数是在Qt 4.3中引入的。
See also addButton() and clickedButton().
void QMessageBox::setWindowModality(Qt::WindowModality windowModality)
	这个函数掩盖了QWidget::setWindowModality()。
	将消息框的模态设置为windowModality。
	在macOS上,如果模式被设置为Qt::WindowModal并且消息框有一个父窗体,那么消息框将是Qt::Sheet,否则消息框将是一个标准的对话框。
	这个函数是在Qt 4.2中引入的。
void QMessageBox::setWindowTitle(const QString &title)
	这个函数掩盖了QWidget::setWindowTitle()。
	将消息框的标题设置为title。在macOS上,窗口标题被忽略(根据macOS指南的要求)。
	这个函数是在Qt 4.2中引入的。
[override virtual protected] void QMessageBox::showEvent(QShowEvent *e)
	Reimplements: QDialog::showEvent(QShowEvent *event).
QMessageBox::StandardButton QMessageBox::standardButton(QAbstractButton *button) const
	返回与给定按钮对应的标准按钮枚举值,如果给定按钮不是标准按钮,则返回NoButton。
	这个函数是在Qt 4.2中引入的。
See also button() and standardButtons().
[static] QMessageBox::StandardButton QMessageBox::warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)
	在指定的父小部件前面打开一个带有给定标题和文本的警告消息框。
	标准按钮被添加到消息框中。defaultButton指定按Enter时使用的按钮。defaultButton必须引用在buttons中给定的按钮。如果defaultButton是QMessageBox::NoButton, QMessageBox会自动选择一个合适的默认值。
	返回被单击的标准按钮的标识。如果按了Esc键,则返回escape键。
	消息框是一个应用程序模态对话框。
	警告:不要在对话框执行期间删除父级。如果您想这样做,您应该使用QMessageBox构造函数之一自己创建对话框。
	这个函数是在Qt 4.2中引入的。
See also question(), information(), and critical(). 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值