两种进度条显示:
QProgressBar和QProgressDialog
下面例子展示两种进度条:
代码:
头文件dialog.h中:
view plain copy to clipboard print ?
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- class Dialog : public QDialog
- {
- Q_OBJECT
-
- public:
- Dialog(QWidget *parent = 0);
- ~Dialog();
- private slots:
- void startProgress();
- private:
- QLabel *FileNum;
- QLineEdit *FileNumLineEdit;
- QLabel *ProgressType;
- QComboBox *comboBox;
- QProgressBar *progressBar;
- QPushButton *startBtn;
- QGridLayout *mainLayout;
- };
#include
#include #include #include #include #include #include class Dialog : public QDialog { Q_OBJECT public: Dialog(QWidget *parent = 0); ~Dialog(); private slots: void startProgress(); private: QLabel *FileNum; QLineEdit *FileNumLineEdit; QLabel *ProgressType; QComboBox *comboBox; QProgressBar *progressBar; QPushButton *startBtn; QGridLayout *mainLayout; };
源文件:
view plain copy to clipboard print ?
- #include "dialog.h"
- #include
- #include
-
- Dialog::Dialog(QWidget *parent)
- : QDialog(parent)
- {
- setWindowTitle(tr("Progress"));
-
- FileNum=new QLabel;
- FileNum->setText(tr("文件数目:"));
- FileNumLineEdit=new QLineEdit;
- FileNumLineEdit->setText(tr("10000"));
-
- ProgressType=new QLabel;
- ProgressType->setText(tr("显示类型:"));
- comboBox=new QComboBox;
- comboBox->addItem(tr("progressBar"));
- comboBox->addItem(tr("progressDialog"));
-
- progressBar=new QProgressBar;
-
- startBtn=new QPushButton;
- startBtn->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(startBtn,3,1);
- mainLayout->setMargin(15);
- mainLayout->setSpacing(10);
-
- connect(startBtn,SIGNAL(clicked()),this,SLOT(startProgress()));
- }
#include "dialog.h" #include #include Dialog::Dialog(QWidget *parent) : QDialog(parent) { setWindowTitle(tr("Progress")); FileNum=new QLabel; FileNum->setText(tr("文件数目:")); FileNumLineEdit=new QLineEdit; FileNumLineEdit->setText(tr("10000")); ProgressType=new QLabel; ProgressType->setText(tr("显示类型:")); comboBox=new QComboBox; comboBox->addItem(tr("progressBar")); comboBox->addItem(tr("progressDialog")); progressBar=new QProgressBar; startBtn=new QPushButton; startBtn->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(startBtn,3,1); mainLayout->setMargin(15); mainLayout->setSpacing(10); connect(startBtn,SIGNAL(clicked()),this,SLOT(startProgress())); }
main函数添加显示中文的代码:
view plain copy to clipboard print ?
- #include
- #include "dialog.h"
- #include
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
- Dialog w;
- w.show();
-
- return a.exec();
- }