QDialog

继承者: 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 modeless 对话框是独立于同一应用程序中其它窗口运转的对话框。文字处理程序中的查找 替换对话框经常是非模态的,以允许用户与应用程序主窗口和对话框进行交互。

非模态对话框被显示使用 PySide.QtGui.QWidget.show() , which returns control to the caller immediately.

若援引 PySide.QtGui.QWidget.show() 函数在隐藏对话框之后,对话框将显示在其原始位置。这是因为窗口管理器决定程序员未明确放置的窗口位置。要保留用户已移动对话框的位置,把其位置保存在 PySide.QtGui.QWidget.closeEvent() 处理程序,然后把对话框移动到该位置,在再次展示它之前。

默认按钮

对话框的 default button is the button that's pressed when the user presses Enter (Return). This button is used to signify that the user accepts the dialog's settings and wants to close the dialog. Use QPushButton.setDefault() , QPushButton.isDefault() and QPushButton.autoDefault() to set and control the dialog's default button.

Esc 键

若用户在对话框中按 Esc 键, QDialog.reject() will be called. This will cause the window to close: The close event 不能是 ignored .

可扩展性

Extensibility is the ability to show the dialog in two ways: a partial dialog that shows the most commonly used options, and a full dialog that shows all the options. Typically an extensible dialog will initially appear as a partial dialog, but with a 更多 toggle button. If the user presses the 更多 button down, the dialog is expanded. The 扩展范例 shows how to achieve extensible dialogs using Qt.

返回值 (模态对话框)

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 扩展范例 标准对话框范例

class PySide.QtGui. QDialog ( [ parent=None [ , f=0 ] ] )
参数:
PySide.QtGui.QDialog. DialogCode

由模态对话框返回的值。

常量 描述
QDialog.Accepted  
QDialog.Rejected  
PySide.QtGui.QDialog. accept ( )

隐藏模态对话框并将结果代码设为 接受 .

PySide.QtGui.QDialog. accepted ( )
PySide.QtGui.QDialog. adjustPosition ( arg__1 )
参数: arg__1 PySide.QtGui.QWidget
PySide.QtGui.QDialog. done ( arg__1 )
参数: 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. exec_ ( )
返回类型: 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.

PySide.QtGui.QDialog. finished ( result )
参数: result PySide.QtCore.int
PySide.QtGui.QDialog. isSizeGripEnabled ( )
返回类型: PySide.QtCore.bool

This property holds whether the size grip is enabled.

A PySide.QtGui.QSizeGrip 被放置在对话框右下角,当此属性被启用时。默认情况下,尺寸握把是禁用的。

PySide.QtGui.QDialog. open ( )

把对话框展示成 window modal dialog ,立即返回。

PySide.QtGui.QDialog. reject ( )

隐藏模态对话框并将结果代码设为 Rejected .

PySide.QtGui.QDialog. rejected ( )
PySide.QtGui.QDialog. result ( )
返回类型: 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 属性。

PySide.QtGui.QDialog. setModal ( modal )
参数: 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.

PySide.QtGui.QDialog. setResult ( r )
参数: 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 .

PySide.QtGui.QDialog. setSizeGripEnabled ( arg__1 )
参数: arg__1 PySide.QtCore.bool

This property holds whether the size grip is enabled.

A PySide.QtGui.QSizeGrip 被放置在对话框右下角,当此属性被启用时。默认情况下,尺寸握把是禁用的。