Two progress bars are displayed:
Qprogressbar and qprogressdialog
The following example shows two progress bars:
Code:
In the header file dialog. h:
#include <QtGui/QDialog>#include <QLabel>#include <QLineEdit>#include <QProgressBar>#include <QComboBox>#include <QPushButton>#include <QGridLayout>class Dialog : public QDialog{ Q_OBJECTpublic: Dialog(QWidget *parent = 0); ~Dialog();private slots: void startProgress();private: QLabel *FileNum; QLineEdit *FileNumLineEdit; QLabel *ProgressType; QComboBox *comboBox; QProgressBar *progressBar; QPushButton *startBtn; QGridLayout *mainLayout;};
Source file:
# Include "dialog. H "# include <qprogressdialog> # include <qfont> dialog: Dialog (qwidget * parent): qdialog (parent) {setwindowtitle (TR (" progress ")); filenum = new qlabel; filenum-> settext (TR ("number of files:"); filenumlineedit = new qlineedit; filenumlineedit-> settext (TR ("10000 ")); progresstype = new qlabel; progresstype-> settext (TR ("display type:"); 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,); mainlayout-> addwidget (filenumlineedit,); mainlayout-> addwidget (progresstype ); mainlayout-> addwidget (ComboBox,); mainlayout-> addwidget (progressbar,); mainlayout-> addwidget (startbtn,); mainlayout-> setmargin (15 ); mainlayout-> setspacing (10); Connect (startbtn, signal (clicked (), this, slot (startprogress ()))}
Void dialog: startprogress () {bool OK; int num = filenumlineedit-> text (). toint (& OK); If (! OK) return; If (ComboBox-> currentindex () = 0) {progressbar-> setrange (0, num); For (INT I = 1; I <= num; I ++) {progressbar-> setvalue (I) ;}} else if (ComboBox-> currentindex () = 1) {qprogressdialog * progressdlg = new qprogressdialog (this ); qfont font ("zysong18030", 12); progressdlg-> setfont (font); progressdlg-> setwindowmodality (QT: windowmodal); progressdlg-> setminimumduration (5 ); progressdlg-> setwindowtitle (TR ("Please wait"); progressdlg-> setlabeltext (TR ("copying ...... "); progressdlg-> setcancelbuttontext (TR (" canceled "); progressdlg-> setrange (0, num); For (INT I = 1; I <= num; I ++) {progressdlg-> setvalue (I); If (progressdlg-> wascanceled () return ;}}}
The main function adds the code to display Chinese characters:
#include <QtGui/QApplication>#include "dialog.h"#include <QTextCodec>int main(int argc, char *argv[]){ QApplication a(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); Dialog w; w.show(); return a.exec();}