Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:使用QProgressDialog创建进度对话框

From Wiki
Jump to: navigation, search

Archived.png存档: 这篇文章是存档,因为考虑到今天它与第三方开发者建立商业解决方案不相关。

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

Article Metadata

代码示例
测试基于
SDK: Qt Garden Pre-release (archived)
设备:: Nokia 5800

兼容于
平台: S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian

文章
关键词: 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槽相连。

后置条件

此代码片段显示了一个有取消按钮的进度对话框,如下图所示:

QtProgressDialog.PNG

例子代码

外部参考

This page was last modified on 11 October 2012, at 01:15.
372 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×