|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.gui.QDialog
com.trolltech.qt.gui.QProgressDialog
public class QProgressDialog
The QProgressDialog
class provides feedback on the progress of a slow operation. 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 beyond minimumDuration()
(4 seconds by default).
Use setMinimum()
and setMaximum()
or the constructor to set the number of "steps" in the operation and call 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 setMinimum()
, and the progress dialog shows that the operation has finished when you call setValue()
with the value set by setMaximum()
as its argument.
The dialog automatically resets and hides itself at the end of the operation. Use setAutoReset()
and setAutoClose()
to change this behavior.
There are two ways of using QProgressDialog
: modal and modeless.
Compared to a modeless QProgressDialog
, a modal QProgressDialog
is simpler to use for the programmer. Do the operation in a loop, call setValue()
at intervals, and check for cancellation with wasCanceled()
. For example:
QProgressDialog progress = new QProgressDialog("Copying files...", "Abort Copy", 0, numFiles, this); progress.setWindowModality(Qt.WindowModality.WindowModal); for (int i = 0; i < numFiles; i++) { 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
(or QObject::timerEvent()
), QSocketNotifier
, or QUrlOperator; 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 call setValue()
at intervals. For example:
// Operationructor public Operation(QObject parent) { super(parent); pd = new QProgressDialog("Operation in progress.", "Cancel", 0, 100); pd.canceled.connect(this, "cancel()"); t = new QTimer(this); t.timeout.connect(this, "perform()"); t.start(0); }In both modes the progress dialog may be customized by replacing the child widgets with custom widgets by using
void perform() { pd.setValue(steps); //... perform one percent of the operation steps++; if (steps > pd.maximum()) t.stop(); }
void cancel() { t.stop(); //... cleanup }
setLabel()
, setBar()
, and setCancelButton()
. The functions setLabelText()
and setCancelButtonText()
set the texts shown. QDialog
, QProgressBar
, GUI Design Handbook: Progress Indicator, Find Files Example, and Pixelator Example.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QDialog |
---|
QDialog.DialogCode |
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Field Summary | |
---|---|
QSignalEmitter.Signal0 |
canceled
This signal is emitted when the cancel button is clicked. |
Fields inherited from class com.trolltech.qt.gui.QDialog |
---|
accepted, finished, rejected |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Constructor Summary | |
---|---|
QProgressDialog()
Constructs a progress dialog. |
|
QProgressDialog(QWidget parent)
Constructs a progress dialog. |
|
QProgressDialog(QWidget parent,
Qt.WindowFlags f)
Constructs a progress dialog. |
|
QProgressDialog(QWidget parent,
Qt.WindowType[] f)
Constructs a progress dialog. |
|
QProgressDialog(java.lang.String labelText,
java.lang.String cancelButtonText,
int minimum,
int maximum)
Constructs a progress dialog. |
|
QProgressDialog(java.lang.String labelText,
java.lang.String cancelButtonText,
int minimum,
int maximum,
QWidget parent)
Constructs a progress dialog. |
|
QProgressDialog(java.lang.String labelText,
java.lang.String cancelButtonText,
int minimum,
int maximum,
QWidget parent,
Qt.WindowFlags f)
Constructs a progress dialog. |
|
QProgressDialog(java.lang.String labelText,
java.lang.String cancelButtonText,
int minimum,
int maximum,
QWidget parent,
Qt.WindowType[] f)
Constructs a progress dialog. |
Method Summary | |
---|---|
boolean |
autoClose()
This property holds whether the dialog gets hidden by reset() . |
boolean |
autoReset()
This property holds whether the progress dialog calls reset() as soon as progress() equals totalSteps(). |
void |
cancel()
Resets the progress dialog. |
protected void |
forceShow()
Shows the dialog if it is still hidden after the algorithm has been started and minimumDuration milliseconds have passed. |
static QProgressDialog |
fromNativePointer(QNativePointer nativePointer)
|
java.lang.String |
labelText()
This property holds the label's text. |
int |
maximum()
This property holds the highest value represented by the progress bar. |
int |
minimum()
This property holds the lowest value represented by the progress bar. |
int |
minimumDuration()
This property holds the time that must pass before the dialog appears. |
void |
reset()
Resets the progress dialog. |
void |
setAutoClose(boolean b)
This property holds whether the dialog gets hidden by reset() . |
void |
setAutoReset(boolean b)
This property holds whether the progress dialog calls reset() as soon as progress() equals totalSteps(). |
void |
setBar(QProgressBar bar)
Sets the progress bar widget to bar. |
void |
setCancelButton(QPushButton button)
Sets the cancel button to the push button, cancelButton. |
void |
setCancelButtonText(java.lang.String arg__1)
Sets the cancel button's text to cancelButtonText. |
void |
setLabel(QLabel label)
Sets the label to label. |
void |
setLabelText(java.lang.String arg__1)
This property holds the label's text. |
void |
setMaximum(int maximum)
This property holds the highest value represented by the progress bar. |
void |
setMinimum(int minimum)
This property holds the lowest value represented by the progress bar. |
void |
setMinimumDuration(int ms)
This property holds the time that must pass before the dialog appears. |
void |
setRange(int minimum,
int maximum)
Sets the progress dialog's minimum and maximum values to minimum and maximum, respectively. |
void |
setValue(int progress)
This property holds the current amount of progress made. |
int |
value()
This property holds the current amount of progress made. |
boolean |
wasCanceled()
This property holds whether the dialog was canceled. |
Methods inherited from class com.trolltech.qt.gui.QDialog |
---|
accept, done, exec, isSizeGripEnabled, reject, result, setModal, setResult, setSizeGripEnabled |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal0 canceled
cancel()
slot by default. wasCanceled()
.
Constructor Detail |
---|
public QProgressDialog(QWidget parent, Qt.WindowType[] f)
Default settings:
setLabelText()
, setCancelButtonText()
, setCancelButton()
, setMinimum()
, and setMaximum()
.
public QProgressDialog(QWidget parent)
Default settings:
setLabelText()
, setCancelButtonText()
, setCancelButton()
, setMinimum()
, and setMaximum()
.
public QProgressDialog()
Default settings:
setLabelText()
, setCancelButtonText()
, setCancelButton()
, setMinimum()
, and setMaximum()
.
public QProgressDialog(QWidget parent, Qt.WindowFlags f)
Default settings:
setLabelText()
, setCancelButtonText()
, setCancelButton()
, setMinimum()
, and setMaximum()
.
public QProgressDialog(java.lang.String labelText, java.lang.String cancelButtonText, int minimum, int maximum, QWidget parent, Qt.WindowType[] f)
The labelText is the text used to remind the user what is progressing.
The cancelButtonText is the text to display on the cancel button, or 0 if no cancel button is to be shown.
The minimum and maximum 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, call setValue(0). As each file is processed call setValue(1), setValue(2), etc., finally calling setValue(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 the QDialog::QDialog() constructor.
setLabelText()
, setLabel()
, setCancelButtonText()
, setCancelButton()
, setMinimum()
, and setMaximum()
.
public QProgressDialog(java.lang.String labelText, java.lang.String cancelButtonText, int minimum, int maximum, QWidget parent)
The labelText is the text used to remind the user what is progressing.
The cancelButtonText is the text to display on the cancel button, or 0 if no cancel button is to be shown.
The minimum and maximum 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, call setValue(0). As each file is processed call setValue(1), setValue(2), etc., finally calling setValue(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 the QDialog::QDialog() constructor.
setLabelText()
, setLabel()
, setCancelButtonText()
, setCancelButton()
, setMinimum()
, and setMaximum()
.
public QProgressDialog(java.lang.String labelText, java.lang.String cancelButtonText, int minimum, int maximum)
The labelText is the text used to remind the user what is progressing.
The cancelButtonText is the text to display on the cancel button, or 0 if no cancel button is to be shown.
The minimum and maximum 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, call setValue(0). As each file is processed call setValue(1), setValue(2), etc., finally calling setValue(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 the QDialog::QDialog() constructor.
setLabelText()
, setLabel()
, setCancelButtonText()
, setCancelButton()
, setMinimum()
, and setMaximum()
.
public QProgressDialog(java.lang.String labelText, java.lang.String cancelButtonText, int minimum, int maximum, QWidget parent, Qt.WindowFlags f)
The labelText is the text used to remind the user what is progressing.
The cancelButtonText is the text to display on the cancel button, or 0 if no cancel button is to be shown.
The minimum and maximum 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, call setValue(0). As each file is processed call setValue(1), setValue(2), etc., finally calling setValue(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 the QDialog::QDialog() constructor.
setLabelText()
, setLabel()
, setCancelButtonText()
, setCancelButton()
, setMinimum()
, and setMaximum()
.
Method Detail |
---|
public final boolean autoClose()
reset()
. The default is true. setAutoReset()
.
public final boolean autoReset()
reset()
as soon as progress() equals totalSteps(). The default is true. setAutoClose()
.
public final void cancel()
wasCanceled()
becomes true until the progress dialog is reset. The progress dialog becomes hidden.
protected final void forceShow()
minimumDuration
milliseconds have passed. setMinimumDuration()
.
public final java.lang.String labelText()
public final int maximum()
minimum
, and setRange()
.
public final int minimum()
maximum
, and setRange()
.
public final int minimumDuration()
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.
public final void reset()
autoClose()
is true. setAutoClose()
, and setAutoReset()
.
public final void setAutoClose(boolean b)
reset()
. The default is true. setAutoReset()
.
public final void setAutoReset(boolean b)
reset()
as soon as progress() equals totalSteps(). The default is true. setAutoClose()
.
public final void setBar(QProgressBar bar)
public final void setCancelButton(QPushButton button)
new()
to create the button. setCancelButtonText()
.
public final void setCancelButtonText(java.lang.String arg__1)
setCancelButton()
.
public final void setLabel(QLabel label)
setLabelText()
.
public final void setLabelText(java.lang.String arg__1)
public final void setMaximum(int maximum)
minimum
, and setRange()
.
public final void setMinimum(int minimum)
maximum
, and setRange()
.
public final void setMinimumDuration(int ms)
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.
public final void setRange(int minimum, int maximum)
If maximum is smaller than minimum, minimum becomes the only legal value.
If the current value falls outside the new range, the progress dialog is reset with reset()
.
minimum
, and maximum
.
public final void setValue(int progress)
QProgressDialog::maximum()
; you can call setValue()
any number of times in-between. Warning: If the progress dialog is modal (see QProgressDialog::QProgressDialog()), this function calls QApplication::processEvents()
, so take care that this does not cause undesirable re-entrancy in your code. For example, don't use a QProgressDialog
inside a paintEvent()
!
minimum
, and maximum
.
public final int value()
QProgressDialog::maximum()
; you can call setValue()
any number of times in-between. Warning: If the progress dialog is modal (see QProgressDialog::QProgressDialog()), this function calls QApplication::processEvents()
, so take care that this does not cause undesirable re-entrancy in your code. For example, don't use a QProgressDialog
inside a paintEvent()
!
minimum
, and maximum
.
public final boolean wasCanceled()
public static QProgressDialog fromNativePointer(QNativePointer nativePointer)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |