QProgressDialog¶
The
QProgressDialog
class provides feedback on the progress of a slow operation. More…
Synopsis¶
Functions¶
def
autoClose
()def
autoReset
()def
labelText
()def
maximum
()def
minimum
()def
minimumDuration
()def
open
(receiver, member)def
setAutoClose
(close)def
setAutoReset
(reset)def
setBar
(bar)def
setCancelButton
(button)def
setLabel
(label)def
value
()def
wasCanceled
()
Slots¶
def
cancel
()def
forceShow
()def
reset
()def
setCancelButtonText
(text)def
setLabelText
(text)def
setMaximum
(maximum)def
setMinimum
(minimum)def
setMinimumDuration
(ms)def
setRange
(minimum, maximum)def
setValue
(progress)
Detailed Description¶
A progress dialog is used to give the user an indication of how long an operation is going to take, and to demonstrate that the application has not frozen. It can also give the user an opportunity to abort the 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.
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 beyondminimumDuration()
(4 seconds by default).Use
setMinimum()
andsetMaximum()
or the constructor to set the number of “steps” in the operation and callsetValue()
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 bysetMinimum()
, and the progress dialog shows that the operation has finished when you callsetValue()
with the value set bysetMaximum()
as its argument.The dialog automatically resets and hides itself at the end of the operation. Use
setAutoReset()
andsetAutoClose()
to change this behavior. Note that if you set a new maximum (usingsetMaximum()
orsetRange()
) that equals your currentvalue()
, the dialog will not close regardless.There are two ways of using
QProgressDialog
: modal and modeless.Compared to a modeless
QProgressDialog
, a modalQProgressDialog
is simpler to use for the programmer. Do the operation in a loop, callsetValue()
at intervals, and check for cancellation withwasCanceled()
. For example: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
QTimer
(ortimerEvent()
) orQSocketNotifier
; or performed in a separate thread. AQProgressBar
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
canceled()
signal to a slot that stops the operation, and callsetValue()
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() #... cleanupIn both modes the progress dialog may be customized by replacing the child widgets with custom widgets by using
setLabel()
,setBar()
, andsetCancelButton()
. The functionssetLabelText()
andsetCancelButtonText()
set the texts shown.
-
class
QProgressDialog
([parent=None[, flags=Qt.WindowFlags()]])¶ QProgressDialog(labelText, cancelButtonText, minimum, maximum[, parent=None[, flags=Qt.WindowFlags()]])
- param parent
- param cancelButtonText
unicode
- param flags
WindowFlags
- param labelText
unicode
- param minimum
int
- param maximum
int
Constructs a progress dialog.
Default settings:
The label text is empty.
The cancel button text is (translated) “Cancel”.
minimum is 0;
maximum is 100
The
parent
argument is dialog’s parent widget. The widget flags,f
, are passed to theQDialog()
constructor.Constructs a progress dialog.
The
labelText
is the text used to remind the user what is progressing.The
cancelButtonText
is the text to display on the cancel button. If QString() is passed then no cancel button is shown.The
minimum
andmaximum
is the number of steps in the operation for which this progress dialog shows progress. For example, if the operation is to examine 50 files, this value minimum value would be 0, and the maximum would be 50. Before examining the first file, callsetValue
(0). As each file is processed callsetValue
(1),setValue
(2), etc., finally callingsetValue
(50) after examining the last file.The
parent
argument is the dialog’s parent widget. The parent,parent
, and widget flags,f
, are passed to theQDialog()
constructor.
-
PySide2.QtWidgets.QProgressDialog.
autoClose
()¶ - Return type
bool
See also
-
PySide2.QtWidgets.QProgressDialog.
autoReset
()¶ - Return type
bool
See also
-
PySide2.QtWidgets.QProgressDialog.
cancel
()¶ Resets the progress dialog.
wasCanceled()
becomes true until the progress dialog is reset. The progress dialog becomes hidden.
-
PySide2.QtWidgets.QProgressDialog.
canceled
()¶
-
PySide2.QtWidgets.QProgressDialog.
forceShow
()¶ Shows the dialog if it is still hidden after the algorithm has been started and
minimumDuration
milliseconds have passed.See also
-
PySide2.QtWidgets.QProgressDialog.
labelText
()¶ - Return type
unicode
See also
-
PySide2.QtWidgets.QProgressDialog.
maximum
()¶ - Return type
int
See also
-
PySide2.QtWidgets.QProgressDialog.
minimum
()¶ - Return type
int
See also
-
PySide2.QtWidgets.QProgressDialog.
minimumDuration
()¶ - Return type
int
See also
-
PySide2.QtWidgets.QProgressDialog.
open
(receiver, member)¶ - Parameters
receiver –
QObject
member – str
Opens the dialog and connects its
canceled()
signal to the slot specified byreceiver
andmember
.The signal will be disconnected from the slot when the dialog is closed.
-
PySide2.QtWidgets.QProgressDialog.
reset
()¶ Resets the progress dialog. The progress dialog becomes hidden if
autoClose()
is true.See also
-
PySide2.QtWidgets.QProgressDialog.
setAutoClose
(close)¶ - Parameters
close –
bool
See also
-
PySide2.QtWidgets.QProgressDialog.
setAutoReset
(reset)¶ - Parameters
reset –
bool
See also
-
PySide2.QtWidgets.QProgressDialog.
setBar
(bar)¶ - Parameters
bar –
QProgressBar
Sets the progress bar widget to
bar
. The progress dialog resizes to fit. The progress dialog takes ownership of the progressbar
which will be deleted when necessary, so do not use a progress bar allocated on the stack.
-
PySide2.QtWidgets.QProgressDialog.
setCancelButton
(button)¶ - Parameters
button –
QPushButton
Sets the cancel button to the 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. IfNone
is passed, no cancel button will be shown.See also
-
PySide2.QtWidgets.QProgressDialog.
setCancelButtonText
(text)¶ - Parameters
text – unicode
Sets the cancel button’s text to
cancelButtonText
. If the text is set to QString() then it will cause the cancel button to be hidden and deleted.See also
-
PySide2.QtWidgets.QProgressDialog.
setLabel
(label)¶ - Parameters
label –
QLabel
Sets the label to
label
. The progress dialog resizes to fit. The label becomes owned by the progress dialog and will be deleted when necessary, so do not pass the address of an object on the stack.See also
-
PySide2.QtWidgets.QProgressDialog.
setLabelText
(text)¶ - Parameters
text – unicode
See also
-
PySide2.QtWidgets.QProgressDialog.
setMinimumDuration
(ms)¶ - Parameters
ms –
int
See also
-
PySide2.QtWidgets.QProgressDialog.
setRange
(minimum, maximum)¶ - Parameters
minimum –
int
maximum –
int
Sets the progress dialog’s minimum and maximum values to
minimum
andmaximum
, respectively.If
maximum
is smaller thanminimum
,minimum
becomes the only legal value.If the current value falls outside the new range, the progress dialog is reset with
reset()
.
-
PySide2.QtWidgets.QProgressDialog.
value
()¶ - Return type
int
See also
-
PySide2.QtWidgets.QProgressDialog.
wasCanceled
()¶ - Return type
bool
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.