📄 qprogressdialog.3qt
字号:
'\" t.TH QProgressDialog 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQProgressDialog \- Feedback on the progress of a slow operation.SH SYNOPSIS\fC#include <qprogressdialog.h>\fR.PPInherits QDialog..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQProgressDialog\fR ( QWidget * creator = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 )".br.ti -1c.BI "\fBQProgressDialog\fR ( const QString & labelText, const QString & cancelButtonText, int totalSteps, QWidget * creator = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 )".br.ti -1c.BI "\fB~QProgressDialog\fR ()".br.ti -1c.BI "void \fBsetLabel\fR ( QLabel * label )".br.ti -1c.BI "void \fBsetCancelButton\fR ( QPushButton * cancelButton )".br.ti -1c.BI "void \fBsetBar\fR ( QProgressBar * bar )".br.ti -1c.BI "bool \fBwasCancelled\fR () const".br.ti -1c.BI "int \fBtotalSteps\fR () const".br.ti -1c.BI "int \fBprogress\fR () const".br.ti -1c.BI "virtual QSize \fBsizeHint\fR () const".br.ti -1c.BI "QString \fBlabelText\fR () const".br.ti -1c.BI "void \fBsetAutoReset\fR ( bool b )".br.ti -1c.BI "bool \fBautoReset\fR () const".br.ti -1c.BI "void \fBsetAutoClose\fR ( bool b )".br.ti -1c.BI "bool \fBautoClose\fR () const".br.ti -1c.BI "int \fBminimumDuration\fR () const".br.in -1c.SS "Public Slots".in +1c.ti -1c.BI "void \fBcancel\fR ()".br.ti -1c.BI "void \fBreset\fR ()".br.ti -1c.BI "void \fBsetTotalSteps\fR ( int totalSteps )".br.ti -1c.BI "void \fBsetProgress\fR ( int progress )".br.ti -1c.BI "void \fBsetProgress\fR ( int progress, int totalSteps )".br.ti -1c.BI "void \fBsetLabelText\fR ( const QString & )".br.ti -1c.BI "void \fBsetCancelButtonText\fR ( const QString & cancelButtonText )".br.ti -1c.BI "void \fBsetMinimumDuration\fR ( int ms )".br.in -1c.SS "Signals".in +1c.ti -1c.BI "void \fBcancelled\fR ()".br.in -1c.SS "Properties".in +1c.ti -1c.BI "bool \fBautoClose\fR - whether the dialog gets hidden by reset()".br.ti -1c.BI "bool \fBautoReset\fR - whether the progress dialog calls reset() as soon as progress() equals totalSteps()".br.ti -1c.BI "QString \fBlabelText\fR - the label's text".br.ti -1c.BI "int \fBminimumDuration\fR - the time that the progress should run for before the dialog opens".br.ti -1c.BI "int \fBprogress\fR - the current amount of progress made".br.ti -1c.BI "int \fBtotalSteps\fR - the total number of steps".br.ti -1c.BI "bool \fBwasCancelled\fR - whether the dialog was cancelled \fI(read " "only" ")\fR".br.in -1c.SS "Protected Slots".in +1c.ti -1c.BI "void \fBforceShow\fR ()".br.in -1c.SH DESCRIPTIONThe QProgressDialog class provides feedback on the progress of a slow operation..PPA 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..PPA 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)..PPUse 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..PPThe dialog automatically resets and hides itself at the end of the operation. Use setAutoReset() and setAutoClose() to change this behavior..PPThere are two ways of using QProgressDialog: modal and modeless..PPUsing 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 wasCancelled(). For example:.PP.nf.brQProgressDialog progress( "Copying files...", "Abort Copy", numFiles,.br this, "progress", TRUE );.brfor ( int i = 0; i < numFiles; i++ ) {.br progress.setProgress( i );.br qApp->processEvents();.br.br if ( progress.wasCancelled() ).br break;.br //... copy one file.br}.brprogress.setProgress( numFiles );.fi.PPA 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..PPYou need to have an event loop to be running, connect the cancelled() signal to a slot that stops the operation, and call setProgress() at intervals. For example:.PP.nf.brOperation::Operation( QObject *parent = 0 ).br : QObject( parent ), steps( 0 ).br{.br pd = new QProgressDialog( "Operation in progress.", "Cancel", 100 );.br connect( pd, SIGNAL(cancelled()), this, SLOT(cancel()) );.br t = new QTimer( this );.br connect( t, SIGNAL(timeout()), this, SLOT(perform()) );.br t->start( 0 );.br}.br.brvoid Operation::perform().br{.br pd->setProgress( steps );.br //... perform one percent of the operation.br steps++;.br if ( steps > pd->totalSteps() )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -