Qt4之UI进度条对话框

有两种形式,下面列举如下所示:

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

	if(typeComboBox->currentIndex() == 0)	/*1.ProgressBar*/
	{
		progressBar->setRange(0,num);
	    for (int i=1; i<num+1; i++)
	    {
	    	progressBar->setValue(i);
	    	/*此处模拟文件拷贝过程*/
	    	QTest::qWait(1000);
	   	}		
	}
	else if(typeComboBox->currentIndex() == 1)/*2.modal ProgressDialog*/
	{
		QProgressDialog *progressDialog = new QProgressDialog(this);
    	QFont font("ZYSong18030",12);
    	progressDialog->setFont(font);		
		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;
	   	}			
	}

Qt4之UI进度条对话框_第1张图片

你可能感兴趣的:(Qt4之UI进度条对话框)