Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.gui
Class QProgressDialog

    java.lang.Object
      com.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

All Implemented Interfaces:
  QPaintDeviceInterface, QtJambiInterface

    public class QProgressDialog

extends QDialog

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("Copying files...", "Abort Copy", 0, numFiles, this);
            progress.setWindowModality(Qt::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:

        // Operation constructor
        Operation::Operation(QObject *parent)
            : QObject(parent), steps(0)
        {
            pd = new QProgressDialog("Operation in progress.", "Cancel", 0, 100);
            connect(pd, SIGNAL(canceled()), this, SLOT(cancel()));
            t = new QTimer(this);
            connect(t, SIGNAL(timeout()), this, SLOT(perform()));
            t->start(0);
        }

        void Operation::perform()
        {
            pd->setValue(steps);
            //... perform one percent of the operation
            steps++;
            if (steps > pd->maximum())
                t->stop();
        }

        void Operation::cancel()
        {
            t->stop();
            //... cleanup
        }

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

The Standard Dialogs example shows how to use `QProgressDialog` as well as other built-in Qt dialogs.

See Also:
  `QDialog`, `QProgressBar`, GUI Design Handbook: Progress Indicator, `Files Example`, `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.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>`

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()` Equivalent to `QProgressDialog`(0, 0).
`QProgressDialog(QWidget parent)` Equivalent to `QProgressDialog`(`parent`, 0).
`QProgressDialog(QWidget parent, Qt.WindowFlags f)` Constructs a progress dialog.
`QProgressDialog(java.lang.String labelText, java.lang.String cancelButtonText, int minimum, int maximum)` Equivalent to `QProgressDialog`(`labelText`, `cancelButtonText`, `minimum`, `maximum`, 0, 0).
`QProgressDialog(java.lang.String labelText, java.lang.String cancelButtonText, int minimum, int maximum, QWidget parent)` Equivalent to `QProgressDialog`(`labelText`, `cancelButtonText`, `minimum`, `maximum`, `parent`, 0).
`QProgressDialog(java.lang.String labelText, java.lang.String cancelButtonText, int minimum, int maximum, QWidget parent, Qt.WindowFlags f)` Constructs a progress dialog.

Method Summary
`boolean` | `autoClose()` Returns whether the dialog gets hidden by `reset`.
`boolean` | `autoReset()` Returns whether the progress dialog calls `reset` as soon as progress() equals totalSteps().
`void` | `cancel()` Resets the progress dialog.
`protected void` | `changeEvent(QEvent arg__1)` This function is reimplemented for internal reasons.
`protected void` | `closeEvent(QCloseEvent arg__1)` This function is reimplemented for internal reasons.
`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)` This function returns the QProgressDialog instance pointed to by nativePointer
`java.lang.String` | `labelText()` Returns the label's text.
`int` | `maximum()` Returns the highest value represented by the progress bar.
`int` | `minimum()` Returns the lowest value represented by the progress bar.
`int` | `minimumDuration()` Returns the time that must pass before the dialog appears.
`void` | `reset()` Resets the progress dialog.
`protected void` | `resizeEvent(QResizeEvent arg__1)` This function is reimplemented for internal reasons.
`void` | `setAutoClose(boolean b)` Sets whether the dialog gets hidden by `reset` to `b`.
`void` | `setAutoReset(boolean b)` Sets whether the progress dialog calls `reset` as soon as progress() equals totalSteps() to `b`.
`void` | `setBar(QProgressBar bar)` Sets the progress bar widget to `bar`.
`void` | `setCancelButton(QPushButton button)` Sets the cancel button to the push button, `button`.
`void` | `setCancelButtonText(java.lang.String arg__1)` Sets the cancel button's text to `arg__1`.
`void` | `setLabel(QLabel label)` Sets the label to `label`.
`void` | `setLabelText(java.lang.String arg__1)` Sets the label's text to `arg__1`.
`void` | `setMaximum(int maximum)` Sets the highest value represented by the progress bar to `maximum`.
`void` | `setMinimum(int minimum)` Sets the lowest value represented by the progress bar to `minimum`.
`void` | `setMinimumDuration(int ms)` Sets the time that must pass before the dialog appears to `ms`.
`void` | `setRange(int minimum, int maximum)` Sets the progress dialog's minimum and maximum values to `minimum` and `maximum`, respectively.
`void` | `setValue(int progress)` Sets the current amount of progress made.
`protected void` | `showEvent(QShowEvent e)` This function is reimplemented for internal reasons.
`QSize` | `sizeHint()` Returns a size that fits the contents of the progress dialog.
`int` | `value()` Returns the current amount of progress made..
`boolean` | `wasCanceled()` Returns whether the dialog was canceled.

Methods inherited from class com.trolltech.qt.gui.QDialog
`accept, adjustPosition, contextMenuEvent, done, eventFilter, exec, isSizeGripEnabled, keyPressEvent, minimumSizeHint, reject, result, setModal, setResult, setSizeGripEnabled, setVisible`

Methods inherited from class com.trolltech.qt.gui.QWidget
`acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, contentsRect, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, ensurePolished, enterEvent, event, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyReleaseEvent, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumWidth, mouseDoubleClickEvent, mouseGrabber, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintEngine, paintEvent, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y`

Methods inherited from class com.trolltech.qt.core.QObject
`blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`disconnect, disconnect, signalSender`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Field Detail

### canceled

    public final QSignalEmitter.Signal0 canceled

  This signal is emitted when the cancel button is clicked. It is connected to the `cancel` slot by default.

  Compatible Slot Signature:
    `void mySlot()`
  See Also:
    `wasCanceled`

Constructor Detail

### QProgressDialog

    public QProgressDialog(QWidget parent)

  Equivalent to `QProgressDialog`(`parent`, 0).

### QProgressDialog

    public QProgressDialog()

  Equivalent to `QProgressDialog`(0, 0).

### QProgressDialog

    public QProgressDialog(QWidget parent,
                           Qt.WindowFlags f)

  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 the QDialog::QDialog() constructor.

  See Also:
    `setLabelText`, `setCancelButtonText`, `setCancelButton`, `setMinimum`, `setMaximum`

### QProgressDialog

    public QProgressDialog(java.lang.String labelText,
                           java.lang.String cancelButtonText,
                           int minimum,
                           int maximum,
                           QWidget parent)

  Equivalent to `QProgressDialog`(`labelText`, `cancelButtonText`, `minimum`, `maximum`, `parent`, 0).

### QProgressDialog

    public QProgressDialog(java.lang.String labelText,
                           java.lang.String cancelButtonText,
                           int minimum,
                           int maximum)

  Equivalent to `QProgressDialog`(`labelText`, `cancelButtonText`, `minimum`, `maximum`, 0, 0).

### QProgressDialog

    public QProgressDialog(java.lang.String labelText,
                           java.lang.String cancelButtonText,
                           int minimum,
                           int maximum,
                           QWidget parent,
                           Qt.WindowFlags f)

  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, 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 and widget flags, `f`, are passed to the QDialog::QDialog() constructor.

  See Also:
    `setLabelText`, `setLabel`, `setCancelButtonText`, `setCancelButton`, `setMinimum`, `setMaximum`

Method Detail

### autoClose

    public final boolean autoClose()

  Returns whether the dialog gets hidden by `reset`.

  The default is true.

  See Also:
    `setAutoClose`, `setAutoReset`

### autoReset

    public final boolean autoReset()

  Returns whether the progress dialog calls `reset` as soon as progress() equals totalSteps().

  The default is true.

  See Also:
    `setAutoReset`, `setAutoClose`

### cancel

    public final void cancel()

  Resets the progress dialog. `wasCanceled` becomes true until the progress dialog is reset. The progress dialog becomes hidden.

### forceShow

    protected final void forceShow()

  Shows the dialog if it is still hidden after the algorithm has been started and `minimumDuration` milliseconds have passed.

  See Also:
    `setMinimumDuration`

### labelText

    public final java.lang.String labelText()

  Returns the label's text.

  The default text is an empty string.

  See Also:
    `setLabelText`

### maximum

    public final int maximum()

  Returns the highest value represented by the progress bar.

  The default is 0.

  See Also:
    `setMaximum`, minimum, `setRange`

### minimum

    public final int minimum()

  Returns the lowest value represented by the progress bar.

  The default is 0.

  See Also:
    `setMinimum`, maximum, `setRange`

### minimumDuration

    public final int minimumDuration()

  Returns 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.

  See Also:
    `setMinimumDuration`

### reset

    public final void reset()

  Resets the progress dialog. The progress dialog becomes hidden if `autoClose` is true.

  See Also:
    `setAutoClose`, `setAutoReset`

### setAutoClose

    public final void setAutoClose(boolean b)

  Sets whether the dialog gets hidden by `reset` to `b`.

  The default is true.

  See Also:
    `autoClose`, `setAutoReset`

### setAutoReset

    public final void setAutoReset(boolean b)

  Sets whether the progress dialog calls `reset` as soon as progress() equals totalSteps() to `b`.

  The default is true.

  See Also:
    `autoReset`, `setAutoClose`

### setBar

    public final void setBar(QProgressBar bar)

  Sets the progress bar widget to `bar`. The progress dialog resizes to fit. The progress dialog takes ownership of the progress `bar` which will be deleted when necessary, so do not use a progress bar allocated on the stack.

### setCancelButton

    public final void setCancelButton(QPushButton button)

  Sets the cancel button to the push button, `button`. 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.

  See Also:
    `setCancelButtonText`

### setCancelButtonText

    public final void setCancelButtonText(java.lang.String arg__1)

  Sets the cancel button's text to `arg__1`.

  See Also:
    `setCancelButton`

### setLabel

    public final void setLabel(QLabel label)

  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`

### setLabelText

    public final void setLabelText(java.lang.String arg__1)

  Sets the label's text to `arg__1`.

  The default text is an empty string.

  See Also:
    `labelText`

### setMaximum

    public final void setMaximum(int maximum)

  Sets the highest value represented by the progress bar to `maximum`.

  The default is 0.

  See Also:
    `maximum`, minimum, `setRange`

### setMinimum

    public final void setMinimum(int minimum)

  Sets the lowest value represented by the progress bar to `minimum`.

  The default is 0.

  See Also:
    `minimum`, maximum, `setRange`

### setMinimumDuration

    public final void setMinimumDuration(int ms)

  Sets the time that must pass before the dialog appears to `ms`.

  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.

  See Also:
    `minimumDuration`

### setRange

    public final void setRange(int minimum,
                               int maximum)

  Sets the progress dialog's minimum and maximum values to `minimum` and `maximum`, respectively.

  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`.

  See Also:
    minimum, maximum

### setValue

    public final void setValue(int progress)

  Sets the current amount of progress made. to `progress`.

  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 `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`!

  See Also:
    `value`, minimum, maximum

### value

    public final int value()

  Returns 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 `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`!

  See Also:
    `setValue`, minimum, maximum

### wasCanceled

    public final boolean wasCanceled()

  Returns whether the dialog was canceled.

### changeEvent

    protected void changeEvent(QEvent arg__1)

  This function is reimplemented for internal reasons.

  Overrides:
    `changeEvent` in class `QWidget`

### closeEvent

    protected void closeEvent(QCloseEvent arg__1)

  This function is reimplemented for internal reasons.

  Overrides:
    `closeEvent` in class `QDialog`
  See Also:
    `event`, `hide`, `close`, `QCloseEvent`, Application Example

### resizeEvent

    protected void resizeEvent(QResizeEvent arg__1)

  This function is reimplemented for internal reasons.

  Overrides:
    `resizeEvent` in class `QDialog`
  See Also:
    `moveEvent`, `event`, `resize`, `QResizeEvent`, `paintEvent`, `Example`

### showEvent

    protected void showEvent(QShowEvent e)

  This function is reimplemented for internal reasons.

  Overrides:
    `showEvent` in class `QDialog`
  See Also:
    `visible`, `event`, `QShowEvent`

### sizeHint

    public QSize sizeHint()

  Returns a size that fits the contents of the progress dialog. The progress dialog resizes itself as required, so you should not need to call this yourself.

  Overrides:
    `sizeHint` in class `QDialog`
  See Also:
    `QSize::isValid`, `minimumSizeHint`, `sizePolicy`, `setMinimumSize`, `updateGeometry`

### fromNativePointer

    public static QProgressDialog fromNativePointer(QNativePointer nativePointer)

  This function returns the QProgressDialog instance pointed to by nativePointer

  Parameters:
    `nativePointer` - the QNativePointer of which object should be returned.

Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD