Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QProgressDialog Class

TheQProgressDialog class provides feedback on the progress of a slow operation.More...

Header:#include <QProgressDialog>
Inherits:QDialog

Properties

Public Functions

QProgressDialog(QWidget * parent = 0, Qt::WindowFlags f = 0)
QProgressDialog(const QString & labelText, const QString & cancelButtonText, int minimum, int maximum, QWidget * parent = 0, Qt::WindowFlags f = 0)
~QProgressDialog()
boolautoClose() const
boolautoReset() const
QStringlabelText() const
intmaximum() const
intminimum() const
intminimumDuration() const
voidopen(QObject * receiver, const char * member)
voidsetAutoClose(bool close)
voidsetAutoReset(bool reset)
voidsetBar(QProgressBar * bar)
voidsetCancelButton(QPushButton * cancelButton)
voidsetLabel(QLabel * label)
intvalue() const
boolwasCanceled() const

Reimplemented Public Functions

virtual QSizesizeHint() const
  • 8 public functions inherited fromQDialog
  • 220 public functions inherited fromQWidget
  • 29 public functions inherited fromQObject
  • 12 public functions inherited fromQPaintDevice

Public Slots

voidcancel()
voidreset()
voidsetCancelButtonText(const QString & cancelButtonText)
voidsetLabelText(const QString & text)
voidsetMaximum(int maximum)
voidsetMinimum(int minimum)
voidsetMinimumDuration(int ms)
voidsetRange(int minimum, int maximum)
voidsetValue(int progress)
  • 5 public slots inherited fromQDialog
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject

Signals

voidcanceled()

Reimplemented Protected Functions

virtual voidchangeEvent(QEvent * ev)
virtual voidcloseEvent(QCloseEvent * e)
virtual voidresizeEvent(QResizeEvent * event)
virtual voidshowEvent(QShowEvent * e)
  • 7 protected functions inherited fromQDialog
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Protected Slots

voidforceShow()
  • 1 protected slot inherited fromQWidget

Additional Inherited Members

  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject
  • 7 protected functions inherited fromQDialog
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Detailed Description

TheQProgressDialog 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 beyondminimumDuration() (4 seconds by default).

UsesetMinimum() andsetMaximum() or the constructor to set the number of "steps" in the operation and callsetValue() 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 bysetMinimum(), and the progress dialog shows that the operation has finished when you callsetValue() with the value set bysetMaximum() as its argument.

The dialog automatically resets and hides itself at the end of the operation. UsesetAutoReset() andsetAutoClose() to change this behavior. Note that if you set a new maximum (usingsetMaximum() orsetRange()) that equals your currentvalue(), the dialog will not close regardless.

There are two ways of usingQProgressDialog: modal and modeless.

Compared to a modelessQProgressDialog, a modalQProgressDialog is simpler to use for the programmer. Do the operation in a loop, callsetValue() at intervals, and check for cancellation withwasCanceled(). 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 onQTimer (orQObject::timerEvent()),QSocketNotifier, orQUrlOperator; or performed in a separate thread. AQProgressBar 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 thecanceled() signal to a slot that stops the operation, and callsetValue() at intervals. For example:

// Operation constructorOperation::Operation(QObject*parent)    :QObject(parent), steps(0){    pd=newQProgressDialog("Operation in progress.","Cancel",0,100);    connect(pd, SIGNAL(canceled()),this, SLOT(cancel()));    t=newQTimer(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 usingsetLabel(),setBar(), andsetCancelButton(). The functionssetLabelText() andsetCancelButtonText() set the texts shown.

A progress dialog shown in the Plastique widget style.

See alsoQDialog,QProgressBar,GUI Design Handbook: Progress Indicator,Find Files Example, andPixelator Example.

Property Documentation

autoClose :bool

This property holds whether the dialog gets hidden by reset().

The default is true.

Access functions:

boolautoClose() const
voidsetAutoClose(bool close)

See alsosetAutoReset().

autoReset :bool

This property holds whether the progress dialog calls reset() as soon as value() equals maximum().

The default is true.

Access functions:

boolautoReset() const
voidsetAutoReset(bool reset)

See alsosetAutoClose().

labelText :QString

This property holds the label's text.

The default text is an empty string.

Access functions:

QStringlabelText() const
voidsetLabelText(const QString & text)

maximum :int

This property holds the highest value represented by the progress bar.

The default is 0.

Access functions:

intmaximum() const
voidsetMaximum(int maximum)

See alsominimum andsetRange().

minimum :int

This property holds the lowest value represented by the progress bar.

The default is 0.

Access functions:

intminimum() const
voidsetMinimum(int minimum)

See alsomaximum andsetRange().

minimumDuration :int

This property holds 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.

Access functions:

intminimumDuration() const
voidsetMinimumDuration(int ms)

value :int

This property holds 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 toQProgressDialog::maximum(); you can call setValue() any number of times in-between.

Warning: If the progress dialog is modal (seeQProgressDialog::QProgressDialog()), setValue() callsQApplication::processEvents(), so take care that this does not cause undesirable re-entrancy in your code. For example, don't use aQProgressDialog inside apaintEvent()!

Access functions:

intvalue() const
voidsetValue(int progress)

See alsominimum andmaximum.

wasCanceled : constbool

This property holds whether the dialog was canceled.

Access functions:

boolwasCanceled() const

Member Function Documentation

QProgressDialog::QProgressDialog(QWidget * parent = 0,Qt::WindowFlags f = 0)

Constructs a progress dialog.

Default settings:

  • The label text is empty.
  • The cancel button text is (translated) "Cancel".
  • minimum is 0;
  • maximum is 100

Theparent argument is dialog's parent widget. The widget flags,f, are passed to theQDialog::QDialog() constructor.

See alsosetLabelText(),setCancelButtonText(),setCancelButton(),setMinimum(), andsetMaximum().

QProgressDialog::QProgressDialog(constQString & labelText, constQString & cancelButtonText,int minimum,int maximum,QWidget * parent = 0,Qt::WindowFlags f = 0)

Constructs a progress dialog.

ThelabelText is the text used to remind the user what is progressing.

ThecancelButtonText is the text to display on the cancel button. If QString() is passed then no cancel button is shown.

Theminimum andmaximum 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, callsetValue(0). As each file is processed callsetValue(1),setValue(2), etc., finally callingsetValue(50) after examining the last file.

Theparent argument is the dialog's parent widget. The parent,parent, and widget flags,f, are passed to theQDialog::QDialog() constructor.

See alsosetLabelText(),setLabel(),setCancelButtonText(),setCancelButton(),setMinimum(), andsetMaximum().

QProgressDialog::~QProgressDialog()

Destroys the progress dialog.

[slot]void QProgressDialog::cancel()

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

[signal]void QProgressDialog::canceled()

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

See alsowasCanceled().

[virtual protected]void QProgressDialog::changeEvent(QEvent * ev)

Reimplemented fromQWidget::changeEvent().

[virtual protected]void QProgressDialog::closeEvent(QCloseEvent * e)

Reimplemented fromQWidget::closeEvent().

[protected slot]void QProgressDialog::forceShow()

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

See alsosetMinimumDuration().

void QProgressDialog::open(QObject * receiver, constchar * member)

This is an overloaded function.

Opens the dialog and connects itsaccepted() signal to the slot specified byreceiver andmember.

The signal will be disconnected from the slot when the dialog is closed.

This function was introduced in Qt 4.5.

[slot]void QProgressDialog::reset()

Resets the progress dialog. The progress dialog becomes hidden ifautoClose() is true.

See alsosetAutoClose() andsetAutoReset().

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

Reimplemented fromQWidget::resizeEvent().

void QProgressDialog::setBar(QProgressBar * bar)

Sets the progress bar widget tobar. The progress dialog resizes to fit. The progress dialog takes ownership of the progressbar 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. If 0 is passed then no cancel button will be shown.

See alsosetCancelButtonText().

[slot]void QProgressDialog::setCancelButtonText(constQString & cancelButtonText)

Sets the cancel button's text tocancelButtonText. If the text is set to QString() then it will cause the cancel button to be hidden and deleted.

See alsosetCancelButton().

void QProgressDialog::setLabel(QLabel * label)

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

[slot]void QProgressDialog::setRange(int minimum,int maximum)

Sets the progress dialog's minimum and maximum values tominimum andmaximum, respectively.

Ifmaximum is smaller thanminimum,minimum becomes the only legal value.

If the current value falls outside the new range, the progress dialog is reset withreset().

See alsominimum andmaximum.

[virtual protected]void QProgressDialog::showEvent(QShowEvent * e)

Reimplemented fromQWidget::showEvent().

[virtual]QSize QProgressDialog::sizeHint() const

Reimplemented fromQWidget::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.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp