- class QProgressDialog¶
The
QProgressDialog
class provides feedback on the progress of a slow operation. More…Synopsis¶
Properties¶
autoCloseᅟ
- Whether the dialog gets hidden by reset()autoResetᅟ
- Whether the progress dialog calls reset() as soon as value() equals maximum()labelTextᅟ
- The label’s textmaximumᅟ
- The highest value represented by the progress barminimumᅟ
- The lowest value represented by the progress barminimumDurationᅟ
- The time that must pass before the dialog appearsvalueᅟ
- The current amount of progress madewasCanceledᅟ
- Whether the dialog was canceled
Methods¶
def
__init__()
def
autoClose()
def
autoReset()
def
labelText()
def
maximum()
def
minimum()
def
open()
def
setAutoClose()
def
setAutoReset()
def
setBar()
def
setLabel()
def
value()
def
wasCanceled()
Slots¶
def
cancel()
def
forceShow()
def
reset()
def
setLabelText()
def
setMaximum()
def
setMinimum()
def
setRange()
def
setValue()
Signals¶
def
canceled()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 range(0, 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 a timer class, such as QChronoTimer (or the more low-level QObject::timerEvent()) or QSocketNotifier; or performed in a separate thread. A
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
canceled()
signal to a slot that stops the operation, and callsetValue()
at intervals. For example:# Operation constructor def __init__(self, parent): super().__init__(parent) self.steps = 0 pd = QProgressDialog("Operation in progress.", "Cancel", 0, 100) pd.canceled.connect(self.cancel) t = QTimer(self) t.timeout.connect(self.perform) t.start(0) def perform(self): pd.setValue(steps) #... perform one percent of the operation steps += 1 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
setLabel()
,setBar()
, andsetCancelButton()
. The functionssetLabelText()
andsetCancelButtonText()
set the texts shown.See also
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property autoCloseᅟ: bool¶
This property holds whether the dialog gets hidden by
reset()
.The default is true.
See also
- Access functions:
- property autoResetᅟ: bool¶
This property holds whether the progress dialog calls
reset()
as soon asvalue()
equalsmaximum()
..The default is true.
See also
- Access functions:
- property labelTextᅟ: str¶
This property holds the label’s text.
The default text is an empty string.
- Access functions:
- property maximumᅟ: int¶
This property holds the highest value represented by the progress bar.
The default is 100.
See also
- Access functions:
- property minimumᅟ: int¶
This property holds the lowest value represented by the progress bar.
The default is 0.
See also
- Access functions:
- property minimumDurationᅟ: int¶
This property holds the time that must pass before the dialog appears.
If the expected duration of the task is less than the 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 minimumDuration, the dialog will pop up after the minimumDuration time or as soon as any progress is set.
If set to 0, the dialog is always shown as soon as any progress is set. The default is 4000 milliseconds.
- Access functions:
- property valueᅟ: 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
minimum()
and finally set it tomaximum()
; you can call setValue() any number of times in-between.Warning
If the progress dialog is modal (see
QProgressDialog()
), setValue() calls QCoreApplication::processEvents(), so take care that this does not cause undesirable re-entrancy in your code. For example, don’t use aQProgressDialog
inside apaintEvent()
!- Access functions:
- property wasCanceledᅟ: bool¶
This property holds whether the dialog was canceled.
- Access functions:
- __init__([parent=None[, flags=Qt.WindowFlags()]])¶
- Parameters:
parent –
QWidget
flags – Combination of
WindowType
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.- __init__(labelText, cancelButtonText, minimum, maximum[, parent=None[, flags=Qt.WindowFlags()]])
- Parameters:
labelText – str
cancelButtonText – str
minimum – int
maximum – int
parent –
QWidget
flags – Combination of
WindowType
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.- autoClose()¶
- Return type:
bool
See also
Getter of property
autoCloseᅟ
.- autoReset()¶
- Return type:
bool
See also
Getter of property
autoResetᅟ
.- cancel()¶
Resets the progress dialog.
wasCanceled()
becomes true until the progress dialog is reset. The progress dialog becomes hidden.- canceled()¶
This signal is emitted when the cancel button is clicked. It is connected to the
cancel()
slot by default.See also
- forceShow()¶
Shows the dialog if it is still hidden after the algorithm has been started and
minimumDuration
milliseconds have passed.See also
- labelText()¶
- Return type:
str
See also
Getter of property
labelTextᅟ
.- maximum()¶
- Return type:
int
See also
Getter of property
maximumᅟ
.- minimum()¶
- Return type:
int
See also
Getter of property
minimumᅟ
.- minimumDuration()¶
- Return type:
int
See also
Getter of property
minimumDurationᅟ
.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.
- reset()¶
Resets the progress dialog. The progress dialog becomes hidden if
autoClose()
is true.See also
- setAutoClose(close)¶
- Parameters:
close – bool
See also
Setter of property
autoCloseᅟ
.- setAutoReset(reset)¶
- Parameters:
reset – bool
See also
Setter of property
autoResetᅟ
.- 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.- 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
- setCancelButtonText(text)¶
- Parameters:
text – str
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
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
- setLabelText(text)¶
- Parameters:
text – str
See also
Setter of property
labelTextᅟ
.Setter of property
maximumᅟ
.Setter of property
minimumᅟ
.- setMinimumDuration(ms)¶
- Parameters:
ms – int
See also
Setter of property
minimumDurationᅟ
.- 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()
.Setter of property
valueᅟ
.- value()¶
- Return type:
int
See also
Getter of property
valueᅟ
.- wasCanceled()¶
- Return type:
bool
Getter of property
wasCanceledᅟ
.