QT中progress的使用

简介:

progress。h

#ifndef PROGRESS_H
#define PROGRESS_H

#include <QtGui>
#include <QtTest>
#include "ui_progress.h"

class progress : public QDialog
{
	Q_OBJECT

public:
	progress(QWidget *parent = 0, Qt::WFlags flags = 0);
	~progress();

	QLabel *numLabel; 
	QLineEdit *numLineEdit;
	QLabel *typeLabel; 
	QComboBox *typeComboBox;

	QProgressBar *progressBar;
	QPushButton *startPushButton;

private:
	Ui::progressClass ui;
	private slots:
		void slotStart();
};

#endif // PROGRESS_H

progress.cpp

#include "progress.h"

progress::progress(QWidget *parent, Qt::WFlags flags)
	: QDialog(parent, flags)
{
	ui.setupUi(this);
	setWindowTitle(tr("Progress"));

	QGridLayout *layout = new QGridLayout( this );  

	numLabel = new QLabel(tr("File Num:")); 
	numLineEdit =  new QLineEdit;
	numLineEdit->setText(tr("10"));

	typeLabel = new QLabel(tr("Progress Type:"));
	typeComboBox = new QComboBox;
	typeComboBox->addItem(tr("ProgressBar"));
	typeComboBox->addItem(tr("ProgressDialog"));

	progressBar = new QProgressBar;

	startPushButton = new QPushButton(tr("Start"));

	layout->addWidget( numLabel, 0, 0 );	
	layout->addWidget( numLineEdit, 0, 1 );
	layout->addWidget( typeLabel, 1, 0 );
	layout->addWidget( typeComboBox, 1, 1 );
	layout->addWidget( progressBar, 2, 0, 1, 2 );
	layout->addWidget( startPushButton, 3, 1 );
	layout->setMargin(15);
	layout->setSpacing(10);

	connect(startPushButton,SIGNAL(clicked()),this,SLOT(slotStart()));
}

progress::~progress()
{

}

void progress::slotStart()
{
	int num=numLineEdit->text().toInt();

	if(typeComboBox->currentIndex() == 0)/*ProgressBar*/
	{
		progressBar->setRange(0,num);
		for (int i=1; i<num+1; i++)
		{
			progressBar->setValue(i);
			/*此处模拟文件拷贝过程*/
			QTest::qWait(1000);
		}		
	}
	else if(typeComboBox->currentIndex() == 1)/*modal ProgressDialog*/
	{
		QProgressDialog *progressDialog = new QProgressDialog(this);		
		progressDialog->setWindowModality(Qt::WindowModal);

		progressDialog->setMinimumDuration(5);
		progressDialog->setWindowTitle(tr("Please Wait"));
		progressDialog->setLabelText(tr("Copying..."));
		progressDialog->setCancelButtonText(tr("Cancel"));		
		progressDialog->setRange(0,num);

		for (int i=1; i<num+1; i++)
		{
			progressDialog->setValue(i);
			qApp->processEvents();
			/*此处模拟文件拷贝过程*/
			QTest::qWait(1000);    	    
			if (progressDialog->wasCanceled())
				return;
		}			
	}

}

main.cpp

#include "progress.h"
#include <QtGui/QApplication>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	progress *w=new progress;
	w->show();
	return a.exec();
}
 

imageimage

目录
相关文章
|
1天前
|
数据采集 人工智能 安全
|
10天前
|
云安全 监控 安全
|
2天前
|
自然语言处理 API
万相 Wan2.6 全新升级发布!人人都能当导演的时代来了
通义万相2.6全新升级,支持文生图、图生视频、文生视频,打造电影级创作体验。智能分镜、角色扮演、音画同步,让创意一键成片,大众也能轻松制作高质量短视频。
882 150
|
15天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1620 8
|
6天前
|
人工智能 前端开发 文件存储
星哥带你玩飞牛NAS-12:开源笔记的进化之路,效率玩家的新选择
星哥带你玩转飞牛NAS,部署开源笔记TriliumNext!支持树状知识库、多端同步、AI摘要与代码高亮,数据自主可控,打造个人“第二大脑”。高效玩家的新选择,轻松搭建专属知识管理体系。
362 152
|
7天前
|
人工智能 自然语言处理 API
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸
一句话生成拓扑图!next-ai-draw-io 结合 AI 与 Draw.io,通过自然语言秒出架构图,支持私有部署、免费大模型接口,彻底解放生产力,绘图效率直接爆炸。
588 152
|
9天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
546 13
|
2天前
|
编解码 人工智能 机器人
通义万相2.6,模型使用指南
智能分镜 | 多镜头叙事 | 支持15秒视频生成 | 高品质声音生成 | 多人稳定对话