📄 qprogressdialog.cpp
字号:
delete d->escapeShortcut; d->escapeShortcut = 0;#endif } int w = qMax(isVisible() ? width() : 0, sizeHint().width()); int h = qMax(isVisible() ? height() : 0, sizeHint().height()); resize(w, h); if (cancelButton) cancelButton->show();}/*! Sets the cancel button's text to \a cancelButtonText. \sa setCancelButton()*/void QProgressDialog::setCancelButtonText(const QString &cancelButtonText){ Q_D(QProgressDialog); d->useDefaultCancelText = false; if (!cancelButtonText.isNull()) { if (d->cancel) d->cancel->setText(cancelButtonText); else setCancelButton(new QPushButton(cancelButtonText, this)); } else { setCancelButton(0); } int w = qMax(isVisible() ? width() : 0, sizeHint().width()); int h = qMax(isVisible() ? height() : 0, sizeHint().height()); resize(w, h);}/*! Sets the progress bar widget to \a bar. The progress dialog resizes to fit. The progress dialog takes ownership of the progress \a bar which will be deleted when necessary, so do not use a progress bar allocated on the stack.*/void QProgressDialog::setBar(QProgressBar *bar){ Q_D(QProgressDialog);#ifndef QT_NO_DEBUG if (value() > 0) qWarning("QProgressDialog::setBar: Cannot set a new progress bar " "while the old one is active");#endif delete d->bar; d->bar = bar; int w = qMax(isVisible() ? width() : 0, sizeHint().width()); int h = qMax(isVisible() ? height() : 0, sizeHint().height()); resize(w, h);}/*! \property QProgressDialog::wasCanceled \brief whether the dialog was canceled*/bool QProgressDialog::wasCanceled() const{ Q_D(const QProgressDialog); return d->cancellation_flag;}/*! \property QProgressDialog::maximum \brief the highest value represented by the progress bar The default is 0. \sa minimum, setRange()*/int QProgressDialog::maximum() const{ Q_D(const QProgressDialog); return d->bar->maximum();}void QProgressDialog::setMaximum(int maximum){ Q_D(QProgressDialog); d->bar->setMaximum(maximum);}/*! \property QProgressDialog::minimum \brief the lowest value represented by the progress bar The default is 0. \sa maximum, setRange()*/int QProgressDialog::minimum() const{ Q_D(const QProgressDialog); return d->bar->minimum();}void QProgressDialog::setMinimum(int minimum){ Q_D(QProgressDialog); d->bar->setMinimum(minimum);}/*! Sets the progress dialog's minimum and maximum values to \a minimum and \a maximum, respectively. If \a maximum is smaller than \a minimum, \a minimum becomes the only legal value. If the current value falls outside the new range, the progress dialog is reset with reset(). \sa minimum, maximum*/void QProgressDialog::setRange(int minimum, int maximum){ Q_D(QProgressDialog); d->bar->setRange(minimum, maximum);}/*! Resets the progress dialog. The progress dialog becomes hidden if autoClose() is true. \sa setAutoClose(), setAutoReset()*/void QProgressDialog::reset(){ Q_D(QProgressDialog);#ifndef QT_NO_CURSOR if (value() >= 0) { if (parentWidget()) parentWidget()->setCursor(d->parentCursor); }#endif if (d->autoClose || d->forceHide) hide(); d->bar->reset(); d->cancellation_flag = false; d->shown_once = false; d->forceTimer->stop();}/*! Resets the progress dialog. wasCanceled() becomes true until the progress dialog is reset. The progress dialog becomes hidden.*/void QProgressDialog::cancel(){ Q_D(QProgressDialog); d->forceHide = true; reset(); d->forceHide = false; d->cancellation_flag = true;}int QProgressDialog::value() const{ Q_D(const QProgressDialog); return d->bar->value();}/*! \property QProgressDialog::value \brief 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()! \sa minimum, maximum*/void QProgressDialog::setValue(int progress){ Q_D(QProgressDialog); if (progress == d->bar->value() || d->bar->value() == -1 && progress == d->bar->maximum()) return; d->bar->setValue(progress); if (d->shown_once) { if (isModal()) qApp->processEvents(); } else { if (progress == 0) { d->starttime.start(); d->forceTimer->start(d->showTime); return; } else { bool need_show; int elapsed = d->starttime.elapsed(); if (elapsed >= d->showTime) { need_show = true; } else { if (elapsed > minWaitTime) { int estimate; int totalSteps = maximum() - minimum(); int myprogress = progress - minimum(); if ((totalSteps - myprogress) >= INT_MAX / elapsed) estimate = (totalSteps - myprogress) / myprogress * elapsed; else estimate = elapsed * (totalSteps - myprogress) / myprogress; need_show = estimate >= d->showTime; } else { need_show = false; } } if (need_show) { int w = qMax(isVisible() ? width() : 0, sizeHint().width()); int h = qMax(isVisible() ? height() : 0, sizeHint().height()); resize(w, h); show(); d->shown_once = true; } }#ifdef Q_WS_MAC QApplication::flush();#endif } if (progress == d->bar->maximum() && d->autoReset) reset();}/*! 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.*/QSize QProgressDialog::sizeHint() const{ Q_D(const QProgressDialog); QSize sh = d->label->sizeHint(); QSize bh = d->bar->sizeHint(); int margin = style()->pixelMetric(QStyle::PM_DefaultTopLevelMargin); int spacing = style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); int h = margin * 2 + bh.height() + sh.height() + spacing; if (d->cancel) h += d->cancel->sizeHint().height() + spacing; return QSize(qMax(200, sh.width() + 2 * margin), h);}/*!\reimp*/void QProgressDialog::resizeEvent(QResizeEvent *){ Q_D(QProgressDialog); d->layout();}/*! \reimp*/void QProgressDialog::changeEvent(QEvent *ev){ Q_D(QProgressDialog); if (ev->type() == QEvent::StyleChange) d->layout(); else if (ev->type() == QEvent::LanguageChange) d->retranslateStrings(); QDialog::changeEvent(ev);}/*! \property QProgressDialog::minimumDuration \brief 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.*/void QProgressDialog::setMinimumDuration(int ms){ Q_D(QProgressDialog); d->showTime = ms; if (d->bar->value() == 0) { d->forceTimer->stop(); d->forceTimer->start(ms); }}int QProgressDialog::minimumDuration() const{ Q_D(const QProgressDialog); return d->showTime;}/*! \reimp*/void QProgressDialog::closeEvent(QCloseEvent *e){ emit canceled(); QDialog::closeEvent(e);}/*! \property QProgressDialog::autoReset \brief whether the progress dialog calls reset() as soon as progress() equals totalSteps() The default is true. \sa setAutoClose()*/void QProgressDialog::setAutoReset(bool b){ Q_D(QProgressDialog); d->autoReset = b;}bool QProgressDialog::autoReset() const{ Q_D(const QProgressDialog); return d->autoReset;}/*! \property QProgressDialog::autoClose \brief whether the dialog gets hidden by reset() The default is true. \sa setAutoReset()*/void QProgressDialog::setAutoClose(bool b){ Q_D(QProgressDialog); d->autoClose = b;}bool QProgressDialog::autoClose() const{ Q_D(const QProgressDialog); return d->autoClose;}/*! \reimp*/void QProgressDialog::showEvent(QShowEvent *e){ Q_D(QProgressDialog); QDialog::showEvent(e); int w = qMax(isVisible() ? width() : 0, sizeHint().width()); int h = qMax(isVisible() ? height() : 0, sizeHint().height()); resize(w, h); d->forceTimer->stop();}/*! Shows the dialog if it is still hidden after the algorithm has been started and minimumDuration milliseconds have passed. \sa setMinimumDuration()*/void QProgressDialog::forceShow(){ Q_D(QProgressDialog); if (d->shown_once || d->cancellation_flag) return; show(); d->shown_once = true;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -