Eneboo - Documentación para desarrolladores
|
The QProgressDialog class provides feedback on the progress of a slow operation.. Más...
#include <qprogressdialog.h>
Slots públicos | |
void | cancel () |
void | reset () |
void | setTotalSteps (int totalSteps) |
void | setProgress (int progress) |
void | setProgress (int progress, int totalSteps) |
void | setLabelText (const QString &) |
void | setCancelButtonText (const QString &) |
void | setMinimumDuration (int ms) |
void | cancel () |
void | reset () |
void | setTotalSteps (int totalSteps) |
void | setProgress (int progress) |
void | setProgress (int progress, int totalSteps) |
void | setLabelText (const QString &) |
void | setCancelButtonText (const QString &) |
void | setMinimumDuration (int ms) |
Señales | |
void | cancelled () |
void | canceled () |
void | cancelled () |
void | canceled () |
Métodos públicos | |
QProgressDialog (QWidget *parent=0, const char *name=0, bool modal=FALSE, WFlags f=0) | |
QProgressDialog (const QString &labelText, const QString &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 |
bool | wasCanceled () const |
int | totalSteps () const |
int | progress () const |
QSize | sizeHint () const |
QString | labelText () const |
void | setAutoReset (bool b) |
bool | autoReset () const |
void | setAutoClose (bool b) |
bool | autoClose () const |
int | minimumDuration () const |
QProgressDialog (QWidget *parent=0, const char *name=0, bool modal=FALSE, WFlags f=0) | |
QProgressDialog (const QString &labelText, const QString &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 |
bool | wasCanceled () const |
int | totalSteps () const |
int | progress () const |
QSize | sizeHint () const |
QString | labelText () const |
void | setAutoReset (bool b) |
bool | autoReset () const |
void | setAutoClose (bool b) |
bool | autoClose () const |
int | minimumDuration () const |
Slots protegidos | |
void | forceShow () |
void | forceShow () |
Métodos protegidos | |
void | resizeEvent (QResizeEvent *) |
void | closeEvent (QCloseEvent *) |
void | styleChange (QStyle &) |
void | showEvent (QShowEvent *e) |
void | resizeEvent (QResizeEvent *) |
void | closeEvent (QCloseEvent *) |
void | styleChange (QStyle &) |
void | showEvent (QShowEvent *e) |
Propiedades | |
bool | wasCancelled |
whether the dialog was canceled | |
bool | wasCanceled |
whether the dialog was canceled | |
int | totalSteps |
the total number of steps | |
int | progress |
the current amount of progress made. | |
bool | autoReset |
whether the progress dialog calls reset() as soon as progress() equals totalSteps() | |
bool | autoClose |
whether the dialog gets hidden by reset() | |
int | minimumDuration |
the time that must pass before the dialog appears | |
QString | labelText |
the label's text |
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 setTotalSteps() (or the constructor) to set the number of "steps" in the operation and call setProgress() as the operation progresses. The step value 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 0, and the progress dialog shows that the operation has finished when you call setProgress() with totalSteps() 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.
Using a modal QProgressDialog is simpler for the programmer, but you must call QApplication::processEvents() or QEventLoop::processEvents(ExcludeUserInput) to keep the event loop running to ensure that the application doesn't freeze. Do the operation in a loop, call setProgress() at intervals, and check for cancellation with wasCanceled(). For example:
QProgressDialog progress( "Copying files...", "Abort Copy", numFiles, this, "progress", TRUE ); for ( int i = 0; i < numFiles; i++ ) { progress.setProgress( i ); qApp->processEvents(); if ( progress.wasCanceled() ) break; //... copy one file } progress.setProgress( 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 setProgress() at intervals. For example:
Operation::Operation( QObject *parent = 0 ) : QObject( parent ), steps( 0 ) { pd = new QProgressDialog( "Operation in progress.", "Cancel", 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->setProgress( steps ); //... perform one percent of the operation steps++; if ( steps > pd->totalSteps() ) 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.
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 (translated) "Cancel". The total number of steps is 100.
The creator argument is the widget to use as the dialog's parent. The name, modal, and the widget flags, f, are passed to the QDialog::QDialog() constructor. If modal is FALSE (the default), you must have an event loop proceeding for any redrawing of the dialog to occur. If modal is TRUE, the dialog ensures that events are processed when needed.
QProgressDialog::QProgressDialog | ( | const QString & | labelText, |
const QString & | cancelButtonText, | ||
int | totalSteps, | ||
QWidget * | creator = 0 , |
||
const char * | name = 0 , |
||
bool | modal = FALSE , |
||
WFlags | f = 0 |
||
) |
Constructs a progress dialog.
The labelText is 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 totalSteps is the total 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 would be 50. Before examining the first file, call setProgress(0). As each file is processed call setProgress(1), setProgress(2), etc., finally calling setProgress(50) after examining the last file.
The creator argument is the widget to use as the dialog's parent. The name, modal, and widget flags, f, are passed to the QDialog::QDialog() constructor. If modal is FALSE (the default), you will must have an event loop proceeding for any redrawing of the dialog to occur. If modal is TRUE, the dialog ensures that events are processed when needed.
QProgressDialog::~QProgressDialog | ( | ) |
Destroys the progress dialog.
QProgressDialog::QProgressDialog | ( | QWidget * | parent = 0 , |
const char * | name = 0 , |
||
bool | modal = FALSE , |
||
WFlags | f = 0 |
||
) |
QProgressDialog::QProgressDialog | ( | const QString & | labelText, |
const QString & | cancelButtonText, | ||
int | totalSteps, | ||
QWidget * | parent = 0 , |
||
const char * | name = 0 , |
||
bool | modal = FALSE , |
||
WFlags | f = 0 |
||
) |
QProgressDialog::~QProgressDialog | ( | ) |
bool QProgressDialog::autoClose | ( | ) | const |
bool QProgressDialog::autoClose | ( | ) | const |
bool QProgressDialog::autoReset | ( | ) | const |
bool QProgressDialog::autoReset | ( | ) | const |
void QProgressDialog::cancel | ( | ) | [slot] |
void QProgressDialog::cancel | ( | ) | [slot] |
Resets the progress dialog. wasCanceled() becomes TRUE until the progress dialog is reset. The progress dialog becomes hidden.
void QProgressDialog::canceled | ( | ) | [signal] |
This signal is emitted when the cancel button is clicked. It is connected to the cancel() slot by default.
void QProgressDialog::canceled | ( | ) | [signal] |
void QProgressDialog::cancelled | ( | ) | [signal] |
Use canceled() instead.
void QProgressDialog::cancelled | ( | ) | [signal] |
void QProgressDialog::closeEvent | ( | QCloseEvent * | e | ) | [protected, virtual] |
Reimplementado de QDialog.
void QProgressDialog::closeEvent | ( | QCloseEvent * | e | ) | [protected, virtual] |
Reimplementado de QDialog.
void QProgressDialog::forceShow | ( | ) | [protected, slot] |
Shows the dialog if it is still hidden after the algorithm has been started and minimumDuration milliseconds have passed.
void QProgressDialog::forceShow | ( | ) | [protected, slot] |
QString QProgressDialog::labelText | ( | ) | const |
QString QProgressDialog::labelText | ( | ) | const |
int QProgressDialog::minimumDuration | ( | ) | const |
int QProgressDialog::minimumDuration | ( | ) | const |
int QProgressDialog::progress | ( | ) | const |
int QProgressDialog::progress | ( | ) | const |
void QProgressDialog::reset | ( | ) | [slot] |
void QProgressDialog::reset | ( | void | ) | [slot] |
Resets the progress dialog. The progress dialog becomes hidden if autoClose() is TRUE.
void QProgressDialog::resizeEvent | ( | QResizeEvent * | ) | [protected, virtual] |
Reimplementado de QDialog.
void QProgressDialog::resizeEvent | ( | QResizeEvent * | ) | [protected, virtual] |
Reimplementado de QDialog.
void QProgressDialog::setAutoClose | ( | bool | b | ) |
void QProgressDialog::setAutoClose | ( | bool | b | ) |
void QProgressDialog::setAutoReset | ( | bool | b | ) |
void QProgressDialog::setAutoReset | ( | bool | b | ) |
void QProgressDialog::setBar | ( | QProgressBar * | ) |
void QProgressDialog::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.
void QProgressDialog::setCancelButton | ( | QPushButton * | cancelButton | ) |
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.
void QProgressDialog::setCancelButton | ( | QPushButton * | ) |
void QProgressDialog::setCancelButtonText | ( | const QString & | cancelButtonText | ) | [slot] |
Sets the cancel button's text to cancelButtonText.
void QProgressDialog::setCancelButtonText | ( | const QString & | ) | [slot] |
void QProgressDialog::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.
void QProgressDialog::setLabel | ( | QLabel * | ) |
void QProgressDialog::setLabelText | ( | const QString & | text | ) | [slot] |
void QProgressDialog::setLabelText | ( | const QString & | ) | [slot] |
void QProgressDialog::setMinimumDuration | ( | int | ms | ) | [slot] |
void QProgressDialog::setMinimumDuration | ( | int | ms | ) | [slot] |
void QProgressDialog::setProgress | ( | int | progress | ) | [slot] |
void QProgressDialog::setProgress | ( | int | progress | ) | [slot] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Sets the current amount of progress to progress and the total number of steps to totalSteps.
void QProgressDialog::setTotalSteps | ( | int | totalSteps | ) | [slot] |
void QProgressDialog::setTotalSteps | ( | int | totalSteps | ) | [slot] |
void QProgressDialog::showEvent | ( | QShowEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive widget show events.
Non-spontaneous show events are sent to widgets immediately before they are shown. The spontaneous show events of top-level widgets are delivered afterwards.
Reimplementado de QWidget.
void QProgressDialog::showEvent | ( | QShowEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
QSize QProgressDialog::sizeHint | ( | ) | const [virtual] |
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.
Reimplementado de QDialog.
void QProgressDialog::styleChange | ( | QStyle & | ) | [protected, virtual] |
This virtual function is called when the style of the widgets changes. oldStyle is the previous GUI style; you can get the new style from style().
Reimplement this function if your widget needs to know when its GUI style changes. You will almost certainly need to update the widget using update().
The default implementation updates the widget including its geometry.
Reimplementado de QWidget.
int QProgressDialog::totalSteps | ( | ) | const |
int QProgressDialog::totalSteps | ( | ) | const |
bool QProgressDialog::wasCanceled | ( | ) | const [inline] |
bool QProgressDialog::wasCanceled | ( | ) | const [inline] |
bool QProgressDialog::wasCancelled | ( | ) | const |
bool QProgressDialog::wasCancelled | ( | ) | const |
bool QProgressDialog::autoClose [read, write] |
bool QProgressDialog::autoReset [read, write] |
whether the progress dialog calls reset() as soon as progress() equals totalSteps()
The default is TRUE.
QString QProgressDialog::labelText [read, write] |
the label's text
The default text is QString::null.
int QProgressDialog::minimumDuration [read, write] |
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.
int QProgressDialog::progress [read, write] |
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::totalSteps(); you can call setProgress() any number of times in-between.
int QProgressDialog::totalSteps [read, write] |
the total number of steps
The default is 0.
bool QProgressDialog::wasCanceled [read] |
whether the dialog was canceled
bool QProgressDialog::wasCancelled [read] |
whether the dialog was canceled
Use wasCanceled instead.