# QProgressDialog Class Reference

Provides feedback on the progress of a slow operation. More...

`#include <qprogressdialog.h>`

Inherits QSemiModal.

List of all member functions.

## Public Members

- QProgressDialog ( QWidget * parent=0, const char * name=0, bool modal=FALSE, WFlags f=0 )
- QProgressDialog ( const char * labelText, const char * cancelButtonText, int totalSteps, QWidget * parent=0, const char * name=0, bool modal=FALSE, WFlags f=0 )
- ~QProgressDialog ()
- void setLabel ( QLabel * )
- void setCancelButton ( QPushButton * )
- void setBar ( QProgressBar * )
- bool wasCancelled () const
- int totalSteps () const
- int progress () const
- virtual QSize sizeHint () const

## Public Slots

- void cancel ()
- void reset ()
- void setTotalSteps ( int totalSteps )
- void setProgress ( int progress )
- void setLabelText ( const char * )
- void setCancelButtonText ( const char * )
- void setMinimumDuration ( int ms )
- int minimumDuration () const

## Signals

- void cancelled ()

## Protected Members

- virtual void resizeEvent ( QResizeEvent * )
- virtual void styleChange ( GUIStyle )

## Detailed Description

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 to perform, and to reassure them that the application has not frozen.

A potential problem with progress dialogs is that it is difficult to know when to use them, as operations take different amounts of time on different computer 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 3 seconds.

Example:

        QProgressDialog progress( "Copying files...", "Abort Copy", numFiles, this );
        for (int i=0; i<numFiles; i++) {
            progress.setProgress( i );
            if ( progress.wasCancelled() )
                break;
            ... // copy one file
        }
        progress.setProgress( numFiles );

See also: QDialog, QProgressBar and GUI Design Handbook: Progress Indicator

Examples: progress/progress.cpp

## Member Function Documentation

### QProgressDialog::QProgressDialog ( QWidget * creator=0, const char * name=0, bool modal=FALSE, WFlags f=0 )

Constructs a progress dialog.

Default settings:

- The label text is empty.
- The cancel button text is "Cancel".
- The total number of steps is 100.

parent, name, modal, and f are sent to the QSemiModal::QSemiModal() constructor. Note that if modal is FALSE (the default), you will need to have an event loop proceeding for any redrawing of the dialog to occur. If it is TRUE, the dialog ensures events are processed when needed.

See also: setLabelText(), setLabel(), setCancelButtonText(), setCancelButton() and setTotalSteps().

### QProgressDialog::QProgressDialog ( const char * labelText, const char * cancelButtonText, int totalSteps, QWidget * creator=0, const char * name=0, bool modal=FALSE, WFlags f=0 )

Constructs a progress dialog.

Arguments:

- labelText is text telling the user what is progressing.
- cancelButtonText is the text on the cancel button, or 0 if no cancel button is to be shown.
- totalSteps is the total number of steps in the operation of which this progress dialog shows the progress. For example, if the operation is to examine 50 files, this value would be 50, then before examining the first file, call setProgress(0), and after examining the last file call setProgress(50).
- name, modal, and f are sent to the QSemiModal::QSemiModal() constructor. Note that if modal is FALSE (the default), you will need to have an event loop proceeding for any redrawing of the dialog to occur. If it is TRUE, the dialog ensures events are processed when needed.

See also: setLabelText(), setLabel(), setCancelButtonText(), setCancelButton() and setTotalSteps().

### QProgressDialog::~QProgressDialog ()

Destroys the progress dialog.

### void QProgressDialog::cancel () `[slot]`

Reset the progress dialog. wasCancelled() becomes TRUE until the progress dialog is reset. The progress dialog becomes hidden.

### void QProgressDialog::cancelled () `[signal]`

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

See also: wasCancelled().

### int QProgressDialog::minimumDuration () const `[slot]`

Returns the currently set minimum duration for the QProgressDialog

See also: setMinimumDuration().

### int QProgressDialog::progress () const

Returns the current amount of progress, or -1 if the progress counting has not started.

See also: setProgress().

### void QProgressDialog::reset () `[slot]`

Reset the progress dialog. The progress dialog becomes hidden.

### void QProgressDialog::resizeEvent ( QResizeEvent * ) `[virtual protected]`

Handles resize events for the progress dialog, sizing the label, dialog, and cancellation button.

Reimplemented from QWidget.

### void QProgressDialog::setBar ( QProgressBar * bar )

Sets the progress bar widget. The progress dialog resizes to fit. The progress bar becomes owned by the progress dialog and will be deleted when necessary.

### void QProgressDialog::setCancelButton ( QPushButton * cancelButton )

Sets the cancellation button. The button 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: setCancelButtonText().

### void QProgressDialog::setCancelButtonText ( const char * cancelButtonText ) `[slot]`

Sets the cancellation button text.

See also: setCancelButton().

### void QProgressDialog::setLabel ( QLabel * label )

Sets the 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().

Examples: progress/progress.cpp

### void QProgressDialog::setLabelText ( const char * text ) `[slot]`

Sets the label text. The progress dialog resizes to fit.

See also: setLabel().

### void QProgressDialog::setMinimumDuration ( int ms ) `[slot]`

The dialog will not appear if the anticipated duration of the progressing task is less than ms milliseconds.

If set to 0 the dialog is always shown as soon as any progress is set.

### void QProgressDialog::setProgress ( int progress ) `[slot]`

Sets the current amount of progress made to prog units of the total number of steps. For the progress dialog to work correctly, you must at least call this with the parameter 0 initially, then later with QProgressDialog::totalSteps(), and you may call it 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 to your code. For example, don't use a QProgressDialog inside a paintEvent()!

See also: progress().

Examples: progress/progress.cpp

### void QProgressDialog::setTotalSteps ( int totalSteps ) `[slot]`

Sets the total number of steps.

See also: totalSteps() and QProgressBar::setTotalSteps().

### QSize QProgressDialog::sizeHint () const `[virtual]`

Returns a size which fits the contents of the progress dialog. The progress dialog resizes itself as required, so this should not be needed in user code.

Reimplemented from QWidget.

### void QProgressDialog::styleChange ( GUIStyle s ) `[virtual protected]`

Ensures layout conforms to style of GUI.

Reimplemented from QWidget.

### int QProgressDialog::totalSteps () const

Returns the total number of steps.

See also: setTotalSteps() and QProgressBar::totalSteps().

Examples: progress/progress.cpp

### bool QProgressDialog::wasCancelled () const

Returns the TRUE if the dialog was cancelled, otherwise FALSE.

See also: setProgress(), cancel() and cancelled().

Examples: progress/progress.cpp

Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):

This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.

It was generated from the following files:

- qprogressdialog.h: 1998/08/21
- qprogressdialog.cpp: 1998/08/18