继承者: QAbstractPrintDialog , QPrintDialog , QAbstractPageSetupDialog , QPageSetupDialog , QFileDialog , QWizard , QProgressDialog , QPrintPreviewDialog , QFontDialog , QMessageBox , QInputDialog , QErrorMessage , QColorDialog
PySide.QtGui.QDialog class is the base class of dialog windows.
对话框窗口是顶级窗口,主要用于短期任务和与用户简短交流。QDialogs 可以是模态 (或非模态) 的。QDialogs 可以提供 return value ,且它们可以有 default buttons 。QDialogs 也可拥有 PySide.QtGui.QSizeGrip 在其右下角,使用 PySide.QtGui.QDialog.setSizeGripEnabled() .
注意: PySide.QtGui.QDialog (and any other widget that has type Qt::Dialog ) 使用父级 Widget 与其它 Qt 类稍有不同。对话框始终是顶层 Widget,但若它有父级,其默认位置是居中父级的顶层 Widget 顶部 (若它本身不在顶层)。它还会共享父级的任务栏条目。
使用重载 QWidget.setParent() function to change the ownership of a PySide.QtGui.QDialog widget. This function allows you to explicitly set the window flags of the reparented widget; using the overloaded function will clear the window flags specifying the window-system properties for the widget (in particular it will reset the Qt.Dialog 标志)。
A modal 对话框是在同一应用程序中阻塞其它可见窗口输入的对话框。用于从用户请求文件名 (或用于设置应用程序首选项) 的通常是模态对话框。对话框可以为 application modal (默认) 或 window modal .
When an application modal dialog is opened, the user must finish interacting with the dialog and close it before they can access any other window in the application. Window modal dialogs only block access to the window associated with the dialog, allowing the user to continue to use other windows in an application.
The most common way to display a modal dialog is to call its exec() function. When the user closes the dialog, exec() will provide a useful return value . Typically, to get the dialog to close and return the appropriate value, we connect a default button, e.g. OK , to the PySide.QtGui.QDialog.accept() slot and a Cancel button to the PySide.QtGui.QDialog.reject() slot. Alternatively you can call the PySide.QtGui.QDialog.done() slot with 接受 or Rejected .
An alternative is to call setModal(true) or PySide.QtGui.QWidget.setWindowModality() ,那么 PySide.QtGui.QWidget.show() 。不像 exec() , PySide.QtGui.QWidget.show() returns control to the caller immediately. Calling setModal(true) is especially useful for progress dialogs, where the user must have the ability to interact with the dialog, e.g. to cancel a long running operation. If you use PySide.QtGui.QWidget.show() and setModal(true) together to perform a long operation, you must call QApplication.processEvents() periodically during processing to enable the user to interact with the dialog. (See PySide.QtGui.QProgressDialog .)
A modeless 对话框是独立于同一应用程序中其它窗口运转的对话框。文字处理程序中的查找 替换对话框经常是非模态的,以允许用户与应用程序主窗口和对话框进行交互。
非模态对话框被显示使用 PySide.QtGui.QWidget.show() , which returns control to the caller immediately.
若援引 PySide.QtGui.QWidget.show() 函数在隐藏对话框之后,对话框将显示在其原始位置。这是因为窗口管理器决定程序员未明确放置的窗口位置。要保留用户已移动对话框的位置,把其位置保存在 PySide.QtGui.QWidget.closeEvent() 处理程序,然后把对话框移动到该位置,在再次展示它之前。
Modal dialogs are often used in situations where a return value is required, e.g. to indicate whether the user pressed OK or Cancel . A dialog can be closed by calling the PySide.QtGui.QDialog.accept() 或 PySide.QtGui.QDialog.reject() slots, and exec() will return 接受 or Rejected as appropriate. The exec() call returns the result of the dialog. The result is also available from PySide.QtGui.QDialog.result() if the dialog has not been destroyed.
In order to modify your dialog's close behavior, you can reimplement the functions PySide.QtGui.QDialog.accept() , PySide.QtGui.QDialog.reject() or PySide.QtGui.QDialog.done() 。 PySide.QtGui.QWidget.closeEvent() function should only be reimplemented to preserve the dialog's position or to override the standard close or reject behavior.
模态对话框:
def countWords(self):
dialog = WordCountDialog(self)
dialog.setWordCount(document().wordCount())
dialog.exec_()
非模态对话框:
def find(self)
if !self.findDialog:
self.findDialog = FindDialog(self)
connect(findDialog, SIGNAL("findNext()"), self, SLOT("findNext()"))
self.findDialog.show()
self.findDialog.raise()
self.findDialog.activateWindow()
另请参阅
PySide.QtGui.QDialogButtonBox PySide.QtGui.QTabWidget PySide.QtGui.QWidget PySide.QtGui.QProgressDialog GUI Design Handbook: Dialogs, Standard 扩展范例 标准对话框范例
| 参数: |
|
|---|
由模态对话框返回的值。
| 常量 | 描述 |
|---|---|
| QDialog.Accepted | |
| QDialog.Rejected |
隐藏模态对话框并将结果代码设为 接受 .
| 参数: | arg__1 – PySide.QtGui.QWidget |
|---|
| 参数: | arg__1 – PySide.QtCore.int |
|---|
关闭对话框并将其结果代码设为 r . If this dialog is shown with exec() , PySide.QtGui.QDialog.done() causes the local event loop to finish, and exec() to return r .
As with QWidget.close() , PySide.QtGui.QDialog.done() deletes the dialog if the Qt.WA_DeleteOnClose flag is set. If the dialog is the application's main widget, the application terminates. If the dialog is the last window closed, the QApplication.lastWindowClosed() 信号被发射。
另请参阅
PySide.QtGui.QDialog.accept() PySide.QtGui.QDialog.reject() QApplication.activeWindow() QApplication.quit()
| 返回类型: | PySide.QtCore.int |
|---|
把对话框展示成 modal dialog ,阻塞直到用户关闭它。函数返回 QDialog.DialogCode 结果。
若对话框是 application modal , users cannot interact with any other window in the same application until they close the dialog. If the dialog is window modal , only interaction with the parent window is blocked while the dialog is open. By default, the dialog is application modal.
| 参数: | result – PySide.QtCore.int |
|---|
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds whether the size grip is enabled.
A PySide.QtGui.QSizeGrip 被放置在对话框右下角,当此属性被启用时。默认情况下,尺寸握把是禁用的。
把对话框展示成 window modal dialog ,立即返回。
隐藏模态对话框并将结果代码设为 Rejected .
| 返回类型: | PySide.QtCore.int |
|---|
In general returns the modal dialog's result code, 接受 or Rejected .
注意
When used from PySide.QtGui.QMessageBox instance the result code type is QMessageBox.StandardButton
Do not call this function if the dialog was constructed with the Qt.WA_DeleteOnClose 属性。
| 参数: | modal – PySide.QtCore.bool |
|---|
此特性保持是否 PySide.QtGui.QWidget.show() should pop up the dialog as modal or modeless.
By default, this property is false and PySide.QtGui.QWidget.show() pops up the dialog as modeless. Setting his property to true is equivalent to setting QWidget.windowModality to Qt.ApplicationModal .
exec() ignores the value of this property and always pops up the dialog as modal.
另请参阅
| 参数: | r – PySide.QtCore.int |
|---|
Sets the modal dialog's result code to i .
注意
We recommend that you use one of the values defined by QDialog.DialogCode .
| 参数: | arg__1 – PySide.QtCore.bool |
|---|
This property holds whether the size grip is enabled.
A PySide.QtGui.QSizeGrip 被放置在对话框右下角,当此属性被启用时。默认情况下,尺寸握把是禁用的。