Archived:使用QProgressDialog创建进度对话框
文章信息
代码示例
测试基于
SDK: Qt Garden Pre-release (archived)
设备:: Nokia 5800
兼容于
平台: S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
文章
关键词: QProgressDialog
翻译:
由 dougcn
最后由 hamishwillee
在 11 Oct 2012 编辑
Contents |
概述
QProgressDialog类提供了对费时操作进度的反馈功能。进度对话框用于给用户指出某个将要进行的操作需要多长时间,以及表明应用程序尚未冻结。 尽管QProgressDialog类似于QProgressBar,但QProgressDialog给了用户放弃操作的机会,而QProgressBar只是仅仅显示进度。这里可以查到How to use QProgressBar in Qt。
此片段可以用自签名。没有用到需要Developer/Symbian签名的任何API。
前提条件
源代码
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ProgressDialog w;
w.showMaximized();
QVBoxLayout* layout = new QVBoxLayout;
QWidget* win = new QWidget;
//The minimum and maximum is the number of steps in the operation for which this progress dialog shows progress.
//for example here 0 and 100.
QProgressDialog* progress = new QProgressDialog("Fetching data...", "Cancel", 0, 100);
//需要的话,将对话框设为模态
progress->setWindowModality(Qt::WindowModal);
layout->addWidget(progress,Qt::AlignCenter);
win->setLayout(layout);
for (int i = 0; i < 100; i++)
{
//set progress value.
progress->setValue(i);
win->show();
//if user click cancel button of dialog.
if (progress->wasCanceled())
break;
}
progress->setValue(100);
win->show();
return a.exec();
}
QProgressDialog的其它有用方法
槽cancel ()重置进度对话框。点击取消按钮后将发出canceled ()信号,缺省与cancel槽相连。
后置条件
此代码片段显示了一个有取消按钮的进度对话框,如下图所示:
例子代码
- 下载例子代码。


(no comments yet)