• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QWizard

    下一话题

    QPrintPreviewDialog

    QProgressDialog

    概要

    函数

    信号

    详细描述

    PySide.QtGui.QProgressDialog class provides feedback on the progress of a slow operation.

    进度对话框用于给予用户操作将花费多长时间的指示,并演示应用程序没有被冻结。它还可以让用户有机会中止操作。

    A common problem with progress dialogs is that it is difficult to know when to use them; operations take different amounts of time on different hardware. PySide.QtGui.QProgressDialog offers a solution to this problem: it estimates the time the operation will take (based on time for steps), and only shows itself if that estimate is beyond PySide.QtGui.QProgressDialog.minimumDuration() (4 seconds by default).

    使用 PySide.QtGui.QProgressDialog.setMinimum() and PySide.QtGui.QProgressDialog.setMaximum() or the constructor to set the number of “steps” in the operation and call PySide.QtGui.QProgressDialog.setValue() as the operation progresses. The number of steps can be chosen arbitrarily. It can be the number of files copied, the number of bytes received, the number of iterations through the main loop of your algorithm, or some other suitable unit. Progress starts at the value set by PySide.QtGui.QProgressDialog.setMinimum() , and the progress dialog shows that the operation has finished when you call PySide.QtGui.QProgressDialog.setValue() with the value set by PySide.QtGui.QProgressDialog.setMaximum() as its argument.

    对话框在操作结束时自动重置并隐藏本身。使用 PySide.QtGui.QProgressDialog.setAutoReset() and PySide.QtGui.QProgressDialog.setAutoClose() to change this behavior. Note that if you set a new maximum (using PySide.QtGui.QProgressDialog.setMaximum() or PySide.QtGui.QProgressDialog.setRange() ) that equals your current PySide.QtGui.QProgressDialog.value() , the dialog will not close regardless.

    There are two ways of using PySide.QtGui.QProgressDialog : modal and modeless.

    Compared to a modeless PySide.QtGui.QProgressDialog , a modal PySide.QtGui.QProgressDialog is simpler to use for the programmer. Do the operation in a loop, call PySide.QtGui.QProgressDialog.setValue() at intervals, and check for cancellation with PySide.QtGui.QProgressDialog.wasCanceled() 。例如:

    progress = QProgressDialog("Copying files...", "Abort Copy", 0, numFiles, self)
    progress.setWindowModality(Qt.WindowModal)
    for i in rang(numFiles):
        progress.setValue(i)
        if progress.wasCanceled():
            break
        #... copy one file
    progress.setValue(numFiles)
    										

    A modeless progress dialog is suitable for operations that take place in the background, where the user is able to interact with the application. Such operations are typically based on PySide.QtCore.QTimer (或 QObject.timerEvent() ), PySide.QtCore.QSocketNotifier ,或 QUrlOperator ; or performed in a separate thread. A PySide.QtGui.QProgressBar in the status bar of your main window is often an alternative to a modeless progress dialog.

    You need to have an event loop to be running, connect the PySide.QtGui.QProgressDialog.canceled() signal to a slot that stops the operation, and call PySide.QtGui.QProgressDialog.setValue() at intervals. For example:

    # Operation constructor
    def __init__(self, parent):
        QObject.__init__(self, parent)
        pd =  QProgressDialog("Operation in progress.", "Cancel", 0, 100)
        connect(pd, SIGNAL("canceled()"), self, SLOT("cancel()"))
        t =  QTimer(self)
        connect(t, SIGNAL("timeout()"), self, SLOT("perform()"))
        t.start(0)
    def perform(self):
        pd.setValue(steps)
        #... perform one percent of the operation
        steps++
        if steps > pd.maximum():
            t.stop()
    def cancel(self):
        t.stop()
        #... cleanup
    									

    In both modes the progress dialog may be customized by replacing the child widgets with custom widgets by using PySide.QtGui.QProgressDialog.setLabel() , PySide.QtGui.QProgressDialog.setBar() ,和 PySide.QtGui.QProgressDialog.setCancelButton() . The functions PySide.QtGui.QProgressDialog.setLabelText() and PySide.QtGui.QProgressDialog.setCancelButtonText() set the texts shown.

    ../../_images/plastique-progressdialog.png

    另请参阅

    PySide.QtGui.QDialog PySide.QtGui.QProgressBar GUI 设计手册:进度指示器 查找文件范例 像素器范例

    class PySide.QtGui. QProgressDialog ( [ parent=None [ , flags=0 ] ] )
    class PySide.QtGui. QProgressDialog ( labelText , cancelButtonText , minimum , maximum [ , parent=None [ , flags=0 ] ] )
    参数:
    • cancelButtonText – unicode
    • flags PySide.QtCore.Qt.WindowFlags
    • labelText – unicode
    • minimum PySide.QtCore.int
    • maximum PySide.QtCore.int
    • parent PySide.QtGui.QWidget
    PySide.QtGui.QProgressDialog. autoClose ( )
    返回类型: PySide.QtCore.bool

    此特性保持对话框是否被隐藏,通过 PySide.QtGui.QProgressDialog.reset() .

    默认为 true。

    PySide.QtGui.QProgressDialog. autoReset ( )
    返回类型: PySide.QtCore.bool

    此特性保持进度对话框是否调用 PySide.QtGui.QProgressDialog.reset() as soon as PySide.QtGui.QProgressDialog.value() 等于 PySide.QtGui.QProgressDialog.maximum() .

    默认为 true。

    PySide.QtGui.QProgressDialog. cancel ( )

    重置进度对话框。 PySide.QtGui.QProgressDialog.wasCanceled() becomes true until the progress dialog is reset. The progress dialog becomes hidden.

    PySide.QtGui.QProgressDialog. canceled ( )
    PySide.QtGui.QProgressDialog. forceShow ( )

    展示对话框,若算法被启动后其仍被隐藏和 PySide.QtGui.QProgressDialog.minimumDuration() 毫秒已过去。

    PySide.QtGui.QProgressDialog. labelText ( )
    返回类型: unicode

    This property holds the label's text.

    默认文本为空字符串。

    PySide.QtGui.QProgressDialog. maximum ( )
    返回类型: PySide.QtCore.int

    This property holds the highest value represented by the progress bar.

    默认为 0。

    PySide.QtGui.QProgressDialog. minimum ( )
    返回类型: PySide.QtCore.int

    This property holds the lowest value represented by the progress bar.

    默认为 0。

    PySide.QtGui.QProgressDialog. minimumDuration ( )
    返回类型: PySide.QtCore.int

    This property holds the time that must pass before the dialog appears.

    If the expected duration of the task is less than the PySide.QtGui.QProgressDialog.minimumDuration() , the dialog will not appear at all. This prevents the dialog popping up for tasks that are quickly over. For tasks that are expected to exceed the PySide.QtGui.QProgressDialog.minimumDuration() , the dialog will pop up after the PySide.QtGui.QProgressDialog.minimumDuration() time or as soon as any progress is set.

    若设为 0,始终一设置任何进度,就会尽快展示对话框。默认为 4000 毫秒。

    PySide.QtGui.QProgressDialog. open ( receiver , member )
    参数:

    这是重载函数。

    打开对话框并连接其 PySide.QtGui.QDialog.accepted() signal to the slot specified by receiver and member .

    信号将断开槽连接,当对话框被关闭时。

    PySide.QtGui.QProgressDialog. reset ( )

    重置进度对话框。进度对话框变为隐藏,若 PySide.QtGui.QProgressDialog.autoClose() 为 true。

    PySide.QtGui.QProgressDialog. setAutoClose ( close )
    参数: close PySide.QtCore.bool

    此特性保持对话框是否被隐藏,通过 PySide.QtGui.QProgressDialog.reset() .

    默认为 true。

    PySide.QtGui.QProgressDialog. setAutoReset ( reset )
    参数: reset PySide.QtCore.bool

    此特性保持进度对话框是否调用 PySide.QtGui.QProgressDialog.reset() as soon as PySide.QtGui.QProgressDialog.value() 等于 PySide.QtGui.QProgressDialog.maximum() .

    默认为 true。

    PySide.QtGui.QProgressDialog. setBar ( bar )
    参数: bar PySide.QtGui.QProgressBar

    将进度栏小部件设为 bar 。进度对话框会重置尺寸以拟合。进度对话框拥有其所有权对于进度 bar 当必要时会被删除,因此不要使用分配在堆栈上的进度条。

    PySide.QtGui.QProgressDialog. setCancelButton ( button )
    参数: button PySide.QtGui.QPushButton

    将取消按钮设为 Push Button (按钮) cancelButton . The progress dialog takes ownership of this button which will be deleted when necessary, so do not pass the address of an object that is on the stack, i.e. use new() to create the button. If 0 is passed then no cancel button will be shown.

    PySide.QtGui.QProgressDialog. setCancelButtonText ( text )
    参数: text – unicode

    将取消按钮的文本设为 cancelButtonText . If the text is set to QString() then it will cause the cancel button to be hidden and deleted.

    PySide.QtGui.QProgressDialog. setLabel ( label )
    参数: label PySide.QtGui.QLabel

    把标签设为 label 。进度对话框会重置尺寸以拟合。标签变为由进度对话框所有,且当必要时会将其删除,因此,不要把对象地址传递到堆栈上。

    PySide.QtGui.QProgressDialog. setLabelText ( text )
    参数: text – unicode

    This property holds the label's text.

    默认文本为空字符串。

    PySide.QtGui.QProgressDialog. setMaximum ( maximum )
    参数: maximum PySide.QtCore.int

    This property holds the highest value represented by the progress bar.

    默认为 0。

    PySide.QtGui.QProgressDialog. setMinimum ( minimum )
    参数: minimum PySide.QtCore.int

    This property holds the lowest value represented by the progress bar.

    默认为 0。

    PySide.QtGui.QProgressDialog. setMinimumDuration ( ms )
    参数: ms PySide.QtCore.int

    This property holds the time that must pass before the dialog appears.

    If the expected duration of the task is less than the PySide.QtGui.QProgressDialog.minimumDuration() , the dialog will not appear at all. This prevents the dialog popping up for tasks that are quickly over. For tasks that are expected to exceed the PySide.QtGui.QProgressDialog.minimumDuration() , the dialog will pop up after the PySide.QtGui.QProgressDialog.minimumDuration() time or as soon as any progress is set.

    若设为 0,始终一设置任何进度,就会尽快展示对话框。默认为 4000 毫秒。

    PySide.QtGui.QProgressDialog. setRange ( minimum , maximum )
    参数:
    • minimum PySide.QtCore.int
    • maximum PySide.QtCore.int

    Sets the progress dialog's minimum and maximum values to minimum and maximum ,分别。

    maximum 小于 minimum , minimum 变为唯一合法值。

    If the current value falls outside the new range, the progress dialog is reset with PySide.QtGui.QProgressDialog.reset() .

    PySide.QtGui.QProgressDialog. setValue ( progress )
    参数: progress PySide.QtCore.int

    This property holds the current amount of progress made..

    For the progress dialog to work as expected, you should initially set this property to 0 and finally set it to QProgressDialog.maximum() ; you can call PySide.QtGui.QProgressDialog.setValue() any number of times in-between.

    警告

    若进度对话框是模态的 (见 QProgressDialog.QProgressDialog() ), PySide.QtGui.QProgressDialog.setValue() calls QApplication.processEvents() , so take care that this does not cause undesirable re-entrancy in your code. For example, don't use a PySide.QtGui.QProgressDialog inside a PySide.QtGui.QWidget.paintEvent() !

    PySide.QtGui.QProgressDialog. value ( )
    返回类型: PySide.QtCore.int

    This property holds the current amount of progress made..

    For the progress dialog to work as expected, you should initially set this property to 0 and finally set it to QProgressDialog.maximum() ; you can call PySide.QtGui.QProgressDialog.setValue() any number of times in-between.

    警告

    若进度对话框是模态的 (见 QProgressDialog.QProgressDialog() ), PySide.QtGui.QProgressDialog.setValue() calls QApplication.processEvents() , so take care that this does not cause undesirable re-entrancy in your code. For example, don't use a PySide.QtGui.QProgressDialog inside a PySide.QtGui.QWidget.paintEvent() !

    PySide.QtGui.QProgressDialog. wasCanceled ( )
    返回类型: PySide.QtCore.bool

    This property holds whether the dialog was canceled.