zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    python基本数据类型
    大学排名之数据库练习
    Python turtle学习笔记
    初学爬虫
    用python进行对乒乓球的比赛分析,并且将该程序进行封装
    新网页
    Python pandas
    十大经典排序算法
    C++的split()函数
    C++多态意义探究
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2440348.html
Copyright © 2011-2022 走看看