2 yxts122 YXTS122 于 2016.02.06 12:31 提问

这文件进度的代码?????

图片说明
图片说明

 #include "progressdlg.h"
#include <QProgressDialog>
#include <QFont>

ProgressDlg::ProgressDlg(QWidget *parent) :
    QDialog(parent)
{
    QFont font("ZYSong18030",12);
    setFont(font);
    setWindowTitle(tr("Progress"));

    FileNum=new QLabel;
    FileNum->setText(tr("文件数目:"));

    FileNumLineEdit=new QLineEdit;
    FileNumLineEdit->setText(tr("100000"));

    ProgressType=new QLabel;
    ProgressType->setText(tr("显示类型:"));

    comboBox=new QComboBox;
    comboBox->addItem(tr("progressBar"));
    comboBox->addItem(tr("progressDialog"));

    progressBar=new QProgressBar;

    starBtn=new QPushButton;
    starBtn->setText(tr("开始"));

    mainLayout=new QGridLayout(this);
    mainLayout->addWidget(FileNum,0,0);
    mainLayout->addWidget(FileNumLineEdit,0,1);
    mainLayout->addWidget(ProgressType,1,0);
    mainLayout->addWidget(comboBox,1,1);
    mainLayout->addWidget(progressBar,2,0,1,2);
    mainLayout->addWidget(starBtn,3,1);
    mainLayout->setMargin(15);
    mainLayout->setSpacing(10);
    connect(starBtn,SIGNAL(clicked(bool)),this,SLOT(startProgress()));
}

void ProgressDlg::startProgress()
{
    bool ok;
    int num=FileNumLineEdit->text().toInt(&ok);
    if(comboBox->currentIndex()==0)
    {
        progressBar->setRange(0,num);
        for(int i=1;i<num+1;i++)
        {
            progressBar->setValue(i);
        }
    }
    else if(comboBox->currentIndex()==1)
    {
        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);
            if(progressDialog->wasCanceled())
                return;
        }
    }
}

ProgressDlg::~ProgressDlg()
{
}

1个回答

YXTS122
YXTS122   2016.02.06 12:37
已采纳

不好意思,发错了,算了,当作和大家一起分享吧!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!