QMessageBox Class Reference

[QtGui module]

该QMessageBox提示类提供通知用户或询问用户问题,并接收应答模式对话框。More…

继承QDialog

Types

  • enum ButtonRole { InvalidRole, AcceptRole, RejectRole, DestructiveRole, ..., ApplyRole }
  • enum Icon { NoIcon, Information, Warning, Critical, Question }
  • enum StandardButton { NoButton, Ok, Save, SaveAll, ..., ButtonMask }
  • class **[StandardButtons]($docs-index.htm)**

Methods

  • __init__ (self, QWidget parent = None)
  • __init__ (self, Icon icon, QString title, QString text, StandardButtons buttons = QMessageBox.NoButton, QWidget parent = None, Qt.WindowFlags flags = Qt.Dialog|Qt.MSWindowsFixedSizeDialogHint)
  • __init__ (self, QString title, QString text, Icon icon, int button0, int button1, int button2, QWidget parent = None, Qt.WindowFlags flags = Qt.Dialog|Qt.MSWindowsFixedSizeDialogHint)
  • addButton (self, QAbstractButton button, ButtonRole role)
  • QPushButton addButton (self, QString text, ButtonRole role)
  • QPushButton addButton (self, StandardButton button)
  • QAbstractButton button (self, StandardButton which)
  • ButtonRole buttonRole (self, QAbstractButton button)
  • list-of-QAbstractButton buttons (self)
  • QString buttonText (self, int button)
  • changeEvent (self, QEvent)
  • QAbstractButton clickedButton (self)
  • closeEvent (self, QCloseEvent)
  • QPushButton defaultButton (self)
  • QString detailedText (self)
  • QAbstractButton escapeButton (self)
  • bool event (self, QEvent e)
  • Icon icon (self)
  • QPixmap iconPixmap (self)
  • QString informativeText (self)
  • keyPressEvent (self, QKeyEvent)
  • open (self)
  • open (self, QObject receiver, SLOT()SLOT() member)
  • open (self, callable receiver)
  • removeButton (self, QAbstractButton button)
  • resizeEvent (self, QResizeEvent)
  • setButtonText (self, int button, QString)
  • setDefaultButton (self, QPushButton button)
  • setDefaultButton (self, StandardButton button)
  • setDetailedText (self, QString text)
  • setEscapeButton (self, QAbstractButton button)
  • setEscapeButton (self, StandardButton button)
  • setIcon (self, Icon)
  • setIconPixmap (self, QPixmap)
  • setInformativeText (self, QString text)
  • setStandardButtons (self, StandardButtons buttons)
  • setText (self, QString)
  • setTextFormat (self, Qt.TextFormat)
  • setWindowModality (self, Qt.WindowModality windowModality)
  • setWindowTitle (self, QString title)
  • showEvent (self, QShowEvent)
  • QSize sizeHint (self)
  • StandardButton standardButton (self, QAbstractButton button)
  • StandardButtons standardButtons (self)
  • QString text (self)
  • Qt.TextFormat textFormat (self)

Static Methods

  • about (QWidget parent, QString caption, QString text)
  • aboutQt (QWidget parent, QString title = QString())
  • StandardButton critical (QWidget parent, QString title, QString text, StandardButtons buttons = QMessageBox.Ok, StandardButton defaultButton = QMessageBox.NoButton)
  • int critical (QWidget parent, QString title, QString text, int button0, int button1, int button2 = 0)
  • int critical (QWidget parent, QString title, QString text, QString button0Text, QString button1Text = QString(), QString button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
  • StandardButton information (QWidget parent, QString title, QString text, StandardButtons buttons = QMessageBox.Ok, StandardButton defaultButton = QMessageBox.NoButton)
  • int information (QWidget parent, QString title, QString text, int button0, int button1 = 0, int button2 = 0)
  • int information (QWidget parent, QString title, QString text, QString button0Text, QString button1Text = QString(), QString button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
  • StandardButton question (QWidget parent, QString title, QString text, StandardButtons buttons = QMessageBox.Ok, StandardButton defaultButton = QMessageBox.NoButton)
  • int question (QWidget parent, QString title, QString text, int button0, int button1 = 0, int button2 = 0)
  • int question (QWidget parent, QString title, QString text, QString button0Text, QString button1Text = QString(), QString button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
  • QPixmap standardIcon (Icon icon)
  • StandardButton warning (QWidget parent, QString title, QString text, StandardButtons buttons = QMessageBox.Ok, StandardButton defaultButton = QMessageBox.NoButton)
  • int warning (QWidget parent, QString title, QString text, int button0, int button1, int button2 = 0)
  • int warning (QWidget parent, QString title, QString text, QString button0Text, QString button1Text = QString(), QString button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)

Qt Signals

  • void buttonClicked (QAbstractButton *)

Detailed Description

该QMessageBox提示类提供通知用户或询问用户问题,并接收应答模式对话框。

一个消息框显示一个主text要提醒用户的情况下,一informative text进一步解释警报或询问用户问题,以及一个可选的detailed text到如果用户请求它提供甚至更多的数据。一个消息框还可以显示iconstandard buttons用于接受用户的响应。

提供两个API使用QMessageBox提示,该物业为基础的API ,和静态函数。调用的静态功能之一是简单的方法,但它比使用基于属性的API,弹性较差,其结果是不够丰富。使用基于属性的API被推荐。

The Property-based API

使用该物业的API ,构建QMessageBox提示的实例,设置所需的属性和调用exec_( )来显示讯息。最简单的配置是仅设置message text属性。

  1. QMessageBox msgBox;
  2. msgBox.setText("The document has been modified.");
  3. msgBox.exec_();

用户必须点击OK按钮来关闭消息框。 GUI的其馀部分被阻塞,直到消息框被驳回。

QMessageBox Class Reference - 图1

比只是提醒用户事件更好的办法是还询问用户该怎么办才好。存储在这个问题informative text属性,并设置standard buttons属性设置为你想要的设置的用户响应的组按钮。这些按钮由合并指定的值StandardButtons使用按位OR运算符。对于按钮的显示顺序是依赖于平台的。例如,在Windows上,Save被显示到左侧Cancel,而在Mac OS上,顺序是相反的。

纪念你的标准按钮之一,是你的default button

  1. QMessageBox msgBox;
  2. msgBox.setText("The document has been modified.");
  3. msgBox.setInformativeText("Do you want to save your changes?");
  4. msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel);
  5. msgBox.setDefaultButton(QMessageBox.Save);
  6. int ret = msgBox.exec_();

这是推荐的做法 Mac OS X Guidelines。类似的准则适用于其他平台,但要注意方式的不同informative text针对不同的平台进行处理。

QMessageBox Class Reference - 图2

exec_()槽返回StandardButtons单击的按钮的值。

  1. switch (ret) {
  2. case QMessageBox.Save:
  3. // Save was clicked
  4. break;
  5. case QMessageBox.Discard:
  6. // Don't Save was clicked
  7. break;
  8. case QMessageBox.Cancel:
  9. // Cancel was clicked
  10. break;
  11. default:
  12. // should never be reached
  13. break;
  14. }

为了给用户更多的信息,以帮助他回答这个问题,设置detailed text属性。如果detailed text属性设置,Show Details…将显示按钮。

QMessageBox Class Reference - 图3

点击Show Details…按钮将显示详细的文字。

QMessageBox Class Reference - 图4

Rich Text and the Text Format Property

detailed text属性总是被解释为纯文本。该main textinformative text性能可以是纯文本或富文本。这些字符串是根据所设定的解释text format属性。默认设置为auto-text

请注意,对于包含XML的元字符的一些纯文本字符串,自动文本rich text detection test可能会失败,从而导致你的纯文本字符串被错误地解释为富文本。在这些罕见的情况下,使用Qt.convertFromPlainText( )到您的纯文本字符串转换为等效的视觉丰富的文本字符串,或将text format属性明确与setTextFormat( ) 。

Severity Levels and the Icon and Pixmap Properties

QMessageBox提示支持四种预定义的消息严重级别,或消息类型,这真的只是不同的预定义的图标,他们每场演出。通过设置指定四个预定义的消息类型之一的icon属性的一个predefined icons。以下规则的指导方针:

| QMessageBox Class Reference - 图5 | Question | For asking a question during normal operations. | | QMessageBox Class Reference - 图6 | Information | For reporting information about normal operations. | | QMessageBox Class Reference - 图7 | Warning | For reporting non-critical errors. | | QMessageBox Class Reference - 图8 | Critical | For reporting critical errors. |

Predefined icons不受QMessageBox提示定义的,而是由式提供。缺省值是No Icon。该消息框,否则相同的所有案件。当使用一个标准的图标,推荐使用表中的一个,或者使用建议您使用平台的风格准则之一。如果没有一个标准的图标是适合你的消息框,你可以通过设置使用自定义图标icon pixmap财产,而不是设置icon属性。

总之,要设置一个图标,用either setIcon( )为标准图标之一,or setIconPixmap()为一个自定义图标。

The Static Functions API

建立消息框与静态函数的API,虽然方便,比使用基于属性的API,弹性较差,因为静态函数签名缺少用于设置参数informative textdetailed text属性。一个工作围绕这一直使用title参数为消息框正文及text参数为消息框翔实的文字。因为这具有使一个不太可读的消息框的明显缺点,平台指引不建议这样做。该Microsoft Windows User Interface Guidelines建议使用application name作为window’s title,这意味着,如果你有除了你的主文本的信息文本,你必须将它连接到text参数。

注意,静态函数签名,相对于它们的键参数,而现在用于设置改变standard buttonsdefault button

静态函数可用于创建information( )question( )warning()和critical( )消息框。

  1. int ret = QMessageBox.warning(this, tr("My Application"),
  2. tr("The document has been modified.\n"
  3. "Do you want to save your changes?"),
  4. QMessageBox.Save | QMessageBox.Discard
  5. | QMessageBox.Cancel,
  6. QMessageBox.Save);

Standard Dialogs示例显示了如何使用QMessageBox提示和其他内置Qt对话框。

Advanced Usage

如果standard buttons不够灵活,你的消息框,您可以使用addButton( )过载,需要一个文本和一个ButtonRoleto添加自定义按钮。该ButtonRole所使用QMessageBox提示来确定屏幕上的按钮的顺序(它根据平台而异)。您可以测试的价值clickedButton( )调用后exec_( ) 。例如,

  1. QMessageBox msgBox;
  2. [QPushButton]($docs-qpushbutton.html) *connectButton = msgBox.addButton(tr("Connect"), QMessageBox.ActionRole);
  3. [QPushButton]($docs-qpushbutton.html) *abortButton = msgBox.addButton(QMessageBox.Abort);
  4. msgBox.exec_();
  5. if (msgBox.clickedButton() == connectButton) {
  6. // connect
  7. } else if (msgBox.clickedButton() == abortButton) {
  8. // abort
  9. }

Default and Escape Keys

默认按钮(即按钮激活时,Enter被按下)可以使用被指定setDefaultButton( ) 。如果没有指定一个缺省按钮, QMessageBox提示试图找到一个基于所述button roles在消息框中使用的按钮。

逃生按钮(按钮激活时,Esc被按下)可以使用被指定setEscapeButton( ) 。如果未指定逃跑按钮, QMessageBox提示尝试使用这些规则,以找到一个:

  1. 如果只有一个按钮,它是激活的按钮时Esc被按下。
  2. 如果有一个Cancel按钮,它是激活按钮时Esc被按下。
  3. 如果恰好有一个按钮有两种the Reject rolethe No role,它是在按钮被激活时Esc被按下。

当不能使用这些规则,按确定的逃生按钮Esc没有任何影响。


Type Documentation

  1. QMessageBox.ButtonRole

该枚举描述了可用于描述按键在按钮框的作用。这些角色的组合作为标志用来形容他们的行为的不同方面。

Constant Value Description
QMessageBox.InvalidRole -1 该按钮是无效的。
QMessageBox.AcceptRole 0 单击该按钮被接受的对话框(如确定)。
QMessageBox.RejectRole 1 单击该按钮会导致被拒绝的对话框(例如取消) 。
QMessageBox.DestructiveRole 2 单击该按钮会导致破坏性的变化(例如,用于舍弃变更) ,然后关闭对话框。
QMessageBox.ActionRole 3 单击该按钮使更改对话框中的元素。
QMessageBox.HelpRole 4 该按钮可点击,请求帮助。
QMessageBox.YesRole 5 该按钮是一个“是”形按钮。
QMessageBox.NoRole 6 该按钮是一个“无”形按钮。
QMessageBox.ApplyRole 8 按钮适用电流的变化。
QMessageBox.ResetRole 7 按钮重置对话框的字段默认值。

See also StandardButton

  1. QMessageBox.Icon

该枚举具有下列值:

Constant Value Description
QMessageBox.NoIcon 0 消息框没有任何图标。
QMessageBox.Question 4 一个图标表明该消息是问一个问题。
QMessageBox.Information 1 一个图标,表示该消息是没有什么两样的。
QMessageBox.Warning 2 一个图标指示该消息是一个警告,但也可以处理。
QMessageBox.Critical 3 一个图标指示该消息表示一个严重的问题。
  1. QMessageBox.StandardButton

这些枚举描述了标准按钮标志。每个按钮都有一个定义ButtonRole

Constant Value Description
QMessageBox.Ok 0x00000400 与定义的一个“OK”按钮AcceptRole
QMessageBox.Open 0x00002000 与定义的“打开”按钮AcceptRole
QMessageBox.Save 0x00000800 与定义的“保存”按钮AcceptRole
QMessageBox.Cancel 0x00400000 “取消”的按钮定义RejectRole
QMessageBox.Close 0x00200000 与定义的“关闭”按钮RejectRole
QMessageBox.Discard 0x00800000 A“放弃”或“不保存”按钮,根据不同的平台上,与定义DestructiveRole
QMessageBox.Apply 0x02000000 一个“应用”的定义的按钮ApplyRole
QMessageBox.Reset 0x04000000 “复位”的定义的按钮ResetRole
QMessageBox.RestoreDefaults 0x08000000 A“还原为默认值”的定义的按钮ResetRole
QMessageBox.Help 0x01000000 与定义的“帮助”按钮HelpRole
QMessageBox.SaveAll 0x00001000 与定义的“全部保存”按钮AcceptRole
QMessageBox.Yes 0x00004000 与定义的“Yes”按钮YesRole
QMessageBox.YesToAll 0x00008000 与定义的“全是”按钮YesRole
QMessageBox.No 0x00010000 与定义的“否”按钮NoRole
QMessageBox.NoToAll 0x00020000 与定义的“全否”按钮NoRole
QMessageBox.Abort 0x00040000 与定义的“中止”按钮RejectRole
QMessageBox.Retry 0x00080000 与定义的“重试”按钮AcceptRole
QMessageBox.Ignore 0x00100000 一个“忽略”的定义的按钮AcceptRole
QMessageBox.NoButton 0x00000000 无效的按钮。

下面的值已过时:

Constant Value Description
QMessageBox.YesAll YesToAll 使用YesToAll代替。
QMessageBox.NoAll NoToAll 改用NoToAll 。
QMessageBox.Default 0x00000100 使用defaultButton的说法information( )warning( )等来代替,或致电setDefaultButton( ) 。
QMessageBox.Escape 0x00000200 Call setEscapeButton( )来代替。
QMessageBox.FlagMask 0x00000300
QMessageBox.ButtonMask ~FlagMask

这个枚举被引入或修改的Qt 4.2 。

该StandardButtons类型是一个typedef为QFlags\u003cStandardButton\u003e 。它存储StandardButton值的或组合。

See also ButtonRolestandardButtons


Method Documentation

  1. QMessageBox.__init__ (self, QWidget parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个消息框,没有文字,没有任何按键。parent被传递到QDialog构造函数。

在Mac OS X ,如果你希望你的消息框显示为Qt.Sheetparent,设置消息框的window modalityQt.WindowModal或者使用open( ) 。否则,消息框将是一个标准的对话框。

  1. QMessageBox.__init__ (self, Icon icon, QString title, QString text, StandardButtons buttons = QMessageBox.NoButton, QWidget parent = None, Qt.WindowFlags flags = Qt.Dialog|Qt.MSWindowsFixedSizeDialogHint)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个消息框,用给定的icontitletext和标准buttons。标准或自定义按钮可以在任何时候使用加addButton( ) 。该parentf参数被传递到QDialog构造函数。

该消息框是一个application modal对话框。

在Mac OS X中,如果parent不为0 ,你希望你的消息框显示为Qt.Sheet该父,设置消息框的window modalityQt.WindowModal(默认值) 。否则,消息框将是一个标准的对话框。

See also setWindowTitle( )setText( )setIcon()和setStandardButtons( ) 。

  1. QMessageBox.__init__ (self, QString title, QString text, Icon icon, int button0, int button1, int button2, QWidget parent = None, Qt.WindowFlags flags = Qt.Dialog|Qt.MSWindowsFixedSizeDialogHint)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

  1. QMessageBox.about (QWidget parent, QString caption, QString text)

显示一个简单的关于与标题框title和文本text。关于对话框的父parent

关于( )会在四个地点合适的图标:

  1. 它喜欢parent->icon()如果存在。
  2. 如果不是,它会尝试包含顶级窗口部件parent
  3. 如果失败,它会尝试active window.
  4. 作为最后的手段,它使用的信息图标。

关于对话框上有标注为“确定”的单一按钮。在Mac OS X中,关于对话框弹出时为无模式窗口,在其他平台上,它是目前应用程序模式。

See also QWidget.windowIcon()和QApplication.activeWindow( ) 。

  1. QMessageBox.aboutQt (QWidget parent, QString title = QString())

显示关于Qt的一个简单的消息框,用给定的title并集中在parent(如果parent不为0 ) 。该消息包括对Qt的正在使用的应用程序的版本号。

这是纳入有用Help一个应用程序的菜单,如图中Menus例子。

QApplication提供此功能的插槽。

在Mac OS X中,关于对话框弹出时为无模式窗口,在其他平台上,它是目前应用程序模式。

See also QApplication.aboutQt( ) 。

  1. QMessageBox.addButton (self, QAbstractButton button, ButtonRole role)

button说法有它的所有权转移给Qt的。

将给定button与指定的消息框role

这个函数中引入了Qt 4.2中。

See also removeButton( )button()和setStandardButtons( ) 。

  1. QPushButton QMessageBox.addButton (self, QString text, ButtonRole role)

[

这是一个重载函数。

创建一个按钮,用给定的text,把它添加到指定的消息框role,并将其返回。

这个函数中引入了Qt 4.2中。

]($docs-qpushbutton.html)

  1. QPushButton QMessageBox.addButton (self, StandardButton button)

[

这是一个重载函数。

增加了一个标准button到消息框,如果它是有效的话,返回按钮。

这个函数中引入了Qt 4.2中。

]($docs-qpushbutton.html)

See also setStandardButtons( ) 。

  1. QAbstractButton QMessageBox.button (self, StandardButton which)

[

返回对应于标准按钮的指针which,或者0,如果标准按钮不能在此消息框存在。

这个函数中引入了Qt 4.2中。

]($docs-qabstractbutton.html)

See also standardButtonsstandardButton( ) 。

  1. ButtonRole QMessageBox.buttonRole (self, QAbstractButton button)

返回指定按钮的作用button。这个函数返回InvalidRole如果button为0或还没有被添加到消息框。

此功能被引入Qt的4.5 。

See also buttons()和addButton( ) 。

  1. list-of-QAbstractButton QMessageBox.buttons (self)

返回所有已添加到消息框按钮的列表。

此功能被引入Qt的4.5 。

See also buttonRole( )addButton()和removeButton( ) 。

  1. QString QMessageBox.buttonText (self, int button)
  1. QMessageBox.changeEvent (self, QEvent)

从重新实现QWidget.changeEvent( ) 。

  1. QAbstractButton QMessageBox.clickedButton (self)

返回由用户,或0点击,如果用户击中按钮Esc键和无escape button设置。

If exec_( )没有被调用尚未返回0。

例如:

  1. [QMessageBox]($docs-qmessagebox.html) messageBox(this);
  2. [QAbstractButton]($docs-qabstractbutton.html) *disconnectButton =
  3. messageBox.addButton(tr("Disconnect"), [QMessageBox]($docs-qmessagebox.html).ActionRole);
  4. ...
  5. messageBox.exec_();
  6. if (messageBox.clickedButton() == disconnectButton) {
  7. ...
  8. }

这个函数中引入了Qt 4.2中。

See also standardButton()和button( ) 。

  1. QMessageBox.closeEvent (self, QCloseEvent)

从重新实现QWidget.closeEvent( ) 。

  1. StandardButton QMessageBox.critical (QWidget parent, QString title, QString text, StandardButtons buttons = QMessageBox.Ok, StandardButton defaultButton = QMessageBox.NoButton)

[

打开一个重要的消息框,用给定的titletext在指定的前parent小工具。

]($docs-qmessagebox.html#StandardButton-enum)

标准buttons添加到消息框。defaultButton指定用于当按钮Enter被按下。defaultButton必须提及的是在给定的一个按钮buttons。如果defaultButton is QMessageBox.NoButtonQMessageBox自动选择一个合适的默认值。

返回被点击的标准按钮的标识。如果Esc被按下而,escape button返回。

该消息框是一个application modal对话框。

Warning:不要删除parent在该对话框的执行。如果你想这样做,你应该用一个自己创建的对话框QMessageBox构造函数。

这个函数中引入了Qt 4.2中。

See also question( )warning()和information( ) 。

  1. int QMessageBox.critical (QWidget parent, QString title, QString text, int button0, int button1, int button2 = 0)
  1. int QMessageBox.critical (QWidget parent, QString title, QString text, QString button0Text, QString button1Text = QString(), QString button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
  1. QPushButton QMessageBox.defaultButton (self)

返回按钮应该是这样的消息框的default button。返回0,如果是没有设置默认按钮。

这个函数中引入了Qt 4.2中。

See also setDefaultButton( )addButton()和QPushButton.setDefault( ) 。

  1. QString QMessageBox.detailedText (self)
  1. QAbstractButton QMessageBox.escapeButton (self)

[

返回逃跑时被按下了启动按钮。

]($docs-qabstractbutton.html)

默认情况下,QMessageBox尝试自动检测逃生按钮,如下所示:

  1. 如果只有一个键,它是由逸出按钮。
  2. 如果有一个Cancel按钮,它是由退出按钮。
  3. 在Mac OS X只,如果恰好有一个按钮的作用QMessageBox.RejectRole,它是由退出按钮。

如果不能自动检测到一个转义按钮,按下Esc没有任何影响。

这个函数中引入了Qt 4.2中。

See also setEscapeButton()和addButton( ) 。

  1. bool QMessageBox.event (self, QEvent e)

从重新实现QObject.event( ) 。

  1. Icon QMessageBox.icon (self)

  1. QPixmap QMessageBox.iconPixmap (self)

  1. StandardButton QMessageBox.information (QWidget parent, QString title, QString text, StandardButtons buttons = QMessageBox.Ok, StandardButton defaultButton = QMessageBox.NoButton)

[

打开一个信息的消息框与给定titletext在指定的前parent小工具。

]($docs-qmessagebox.html#StandardButton-enum)

标准buttons添加到消息框。defaultButton指定用于当按钮Enter被按下。defaultButton必须提及的是在给定的一个按钮buttons。如果defaultButton is QMessageBox.NoButtonQMessageBox自动选择一个合适的默认值。

返回被点击的标准按钮的标识。如果Esc被按下而,escape button返回。

该消息框是一个application modal对话框。

Warning:不要删除parent在该对话框的执行。如果你想这样做,你应该用一个自己创建的对话框QMessageBox构造函数。

这个函数中引入了Qt 4.2中。

See also question( )warning()和critical( ) 。

  1. int QMessageBox.information (QWidget parent, QString title, QString text, int button0, int button1 = 0, int button2 = 0)
  1. int QMessageBox.information (QWidget parent, QString title, QString text, QString button0Text, QString button1Text = QString(), QString button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
  1. QString QMessageBox.informativeText (self)
  1. QMessageBox.keyPressEvent (self, QKeyEvent)

从重新实现QWidget.keyPressEvent( ) 。

  1. QMessageBox.open (self)

这是一个重载函数。

在打开的对话框并连接其finished()或buttonClicked()信号到由指定的槽receivermember。如果在槽member有一个指针,它的第一个参数的连接是buttonClicked( ),否则该连接是finished( ) 。

该信号会从插槽中断开时,关闭对话框。

  1. QMessageBox.open (self, QObject receiver, SLOT()SLOT() member)
  1. QMessageBox.open (self, callable receiver)
  1. StandardButton QMessageBox.question (QWidget parent, QString title, QString text, StandardButtons buttons = QMessageBox.Ok, StandardButton defaultButton = QMessageBox.NoButton)

[

打开一个疑问消息框,用给定的titletext在指定的前parent小工具。

]($docs-qmessagebox.html#StandardButton-enum)

标准buttons添加到消息框。defaultButton指定用于当按钮Enter被按下。defaultButton必须提及的是在给定的一个按钮buttons。如果defaultButton is QMessageBox.NoButtonQMessageBox自动选择一个合适的默认值。

返回被点击的标准按钮的标识。如果Esc被按下而,escape button返回。

该消息框是一个application modal对话框。

Warning:不要删除parent在该对话框的执行。如果你想这样做,你应该用一个自己创建的对话框QMessageBox构造函数。

这个函数中引入了Qt 4.2中。

See also information( )warning()和critical( ) 。

  1. int QMessageBox.question (QWidget parent, QString title, QString text, int button0, int button1 = 0, int button2 = 0)
  1. int QMessageBox.question (QWidget parent, QString title, QString text, QString button0Text, QString button1Text = QString(), QString button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)
  1. QMessageBox.removeButton (self, QAbstractButton button)

button争论

移除button从而不删除它的按钮盒。

这个函数中引入了Qt 4.2中。

See also addButton()和setStandardButtons( ) 。

  1. QMessageBox.resizeEvent (self, QResizeEvent)

从重新实现QWidget.resizeEvent( ) 。

  1. QMessageBox.setButtonText (self, int button, QString)
  1. QMessageBox.setDefaultButton (self, QPushButton button)

设置消息框的default buttonbutton

这个函数中引入了Qt 4.2中。

See also defaultButton( )addButton()和QPushButton.setDefault( ) 。

  1. QMessageBox.setDefaultButton (self, StandardButton button)

设置消息框的default buttonbutton

此功能被引入Qt的4.3 。

See also addButton()和QPushButton.setDefault( ) 。

  1. QMessageBox.setDetailedText (self, QString text)
  1. QMessageBox.setEscapeButton (self, QAbstractButton button)

设置被激活​​按钮时Escape键被按下button

这个函数中引入了Qt 4.2中。

See also escapeButton( )addButton()和clickedButton( ) 。

  1. QMessageBox.setEscapeButton (self, StandardButton button)

设置被激活​​的按钮时,Escape键被按下button

此功能被引入Qt的4.3 。

See also addButton()和clickedButton( ) 。

  1. QMessageBox.setIcon (self, Icon)
  1. QMessageBox.setIconPixmap (self, QPixmap)
  1. QMessageBox.setInformativeText (self, QString text)
  1. QMessageBox.setStandardButtons (self, StandardButtons buttons)
  1. QMessageBox.setText (self, QString)
  1. QMessageBox.setTextFormat (self, Qt.TextFormat)
  1. QMessageBox.setWindowModality (self, Qt.WindowModality windowModality)

该功能的阴影QWidget.setWindowModality( ) 。

设置消息框的样式,以windowModality

在Mac OS X中,如果模式设置为Qt.WindowModal并且该消息框有父,则消息框将是一个Qt.Sheet,否则,消息框将是一个标准的对话框。

这个函数中引入了Qt 4.2中。

  1. QMessageBox.setWindowTitle (self, QString title)

该功能的阴影QWidget.setWindowTitle( ) 。

设置消息框的标题title。在Mac OS X ,窗口标题将被忽略(如需要Mac OS X的指引) 。

这个函数中引入了Qt 4.2中。

  1. QMessageBox.showEvent (self, QShowEvent)

从重新实现QWidget.showEvent( ) 。

  1. QSize QMessageBox.sizeHint (self)

  1. StandardButton QMessageBox.standardButton (self, QAbstractButton button)

返回对应于给定的标准按钮枚举值buttonNoButton如果给定的button不是一个标准的按钮。

这个函数中引入了Qt 4.2中。

See also button()和standardButtons( ) 。

  1. StandardButtons QMessageBox.standardButtons (self)

  1. QPixmap QMessageBox.standardIcon (Icon icon)

[

  1. QString QMessageBox.text (self)

](qpixmap.html)

  1. Qt.TextFormat QMessageBox.textFormat (self)

  1. StandardButton QMessageBox.warning (QWidget parent, QString title, QString text, StandardButtons buttons = QMessageBox.Ok, StandardButton defaultButton = QMessageBox.NoButton)

[

打开一个警告消息框与给定titletext在指定的前parent小工具。

]($docs-qmessagebox.html#StandardButton-enum)

标准buttons添加到消息框。defaultButton指定用于当按钮Enter被按下。defaultButton必须提及的是在给定的一个按钮buttons。如果defaultButton is QMessageBox.NoButtonQMessageBox自动选择一个合适的默认值。

返回被点击的标准按钮的标识。如果Esc被按下而,escape button返回。

该消息框是一个application modal对话框。

Warning:不要删除parent在该对话框的执行。如果你想这样做,你应该用一个自己创建的对话框QMessageBox构造函数。

这个函数中引入了Qt 4.2中。

See also question( )information()和critical( ) 。

  1. int QMessageBox.warning (QWidget parent, QString title, QString text, int button0, int button1, int button2 = 0)
  1. int QMessageBox.warning (QWidget parent, QString title, QString text, QString button0Text, QString button1Text = QString(), QString button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1)

Qt Signal Documentation

  1. void buttonClicked (QAbstractButton *)

这是该信号的默认超载。

每当一个按钮被点击里面的这个信号被发射QMessageBox。被点击在返回的按钮button