Qt对话框之进度条

6,744次阅读
没有评论

共计 2096 个字符,预计需要花费 6 分钟才能阅读完成。

博主开始利用业余时间学习QT了,完成学习写界面的伟大理想。。。。。。。Qt初步学习到对话框,晚上看着给的截面图尝试自己写代码完成界面。。。。

简单介绍下:

Qt进度条有两种

1、QProgressBar

2、QProgressDialog

下面给出代码完成这两种进度条的实现:

 

 

#ifndef DIALOG_H
#define DIALOG_H

#include 
#include
#include
#include
#include
#include
#include
class Dialog : public QDialog
{
    Q_OBJECT

public:
    Dialog(QWidget *parent = 0);
    ~Dialog();
private slots:
    void showprogress();
private:
    QLabel *filename;
    QLineEdit *filenum;
    QLabel *showlabel;
    QComboBox *showshow;
    QProgressBar * progress;
    QPushButton *start;
    QGridLayout *mainlayout;

};

#endif // DIALOG_H
#include "dialog.h"
#include
Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
{

    setWindowTitle(tr("Progress"));
    QFont fontdefine("ZYSong18030",12);
    setFont(fontdefine);
    filename=new QLabel;
    filename->setText(tr("文件数目:"));
    filenum=new QLineEdit ;
    filenum->setText(tr("10000"));
    showlabel=new QLabel;
    showlabel->setText(tr("显示类型:"));
    showshow=new QComboBox;
    showshow->addItem(tr("progressbar"));
    showshow->addItem(tr("progressdialog"));
    progress=new QProgressBar;
    start=new QPushButton;
    start->setText(tr("开始"));
    mainlayout=new QGridLayout(this);
    mainlayout->addWidget(filename,0,0);
    mainlayout->addWidget(filenum,0,1);
    mainlayout->addWidget(showlabel,1,0);
    mainlayout->addWidget(showshow,1,1);
    mainlayout->addWidget(progress,2,0,1,2);
    mainlayout->addWidget(start,3,1);
    mainlayout->setMargin(15);
    mainlayout->setSpacing(10);
    connect(start,SIGNAL(clicked()),this,SLOT(showprogress()));


}
void Dialog::showprogress()
{
    bool ok;
    int num=filenum->text().toInt(&ok);
    if (showshow->currentIndex()==0)
    {
        progress->setRange(0,num);
        for(int i=0;isetValue(i);
        }

    }else if(showshow->currentIndex()==1)
    {
       QProgressDialog *progressdialog=new QProgressDialog(this);
       QFont fontdefine("ZYSong18030",12);
       setFont(fontdefine);
       progressdialog->setWindowModality(Qt::WindowModal);
       progressdialog->setMinimumDuration(5);
       progressdialog->setWindowTitle(tr("等待"));
       progressdialog->setLabelText(tr("copy..."));
       progressdialog->setCancelButton(new QPushButton(tr("cancel")));
       progressdialog->setRange(0,num);
       for(int i=0;isetValue(i);
           if(progressdialog->wasCanceled())
               return;
       }


    }
}

Dialog::~Dialog()
{

}
#include "dialog.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Dialog w;
    w.show();

    return a.exec();
}
正文完
请博主喝杯咖啡吧!
post-qrcode
 
admin
版权声明:本站原创文章,由 admin 2016-03-24发表,共计2096字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码