Usually we download things there will always be a display of the number of downloads of the progress bar, we come to realize today.
Here are two ways to display
Can choose, the first one is used
The Qprogressbar control, and the second one uses the Qprogressdialog control
Progressdlg.h
/*** Book: "QT5 Development and examples" * function: In order to achieve the display of the progress bar * file: progressdlg.h* time: January 2, 2015 15:27:10* Author: cutter_point*/#ifndef progressdlg_h# Define Progressdlg_h#include <QDialog> #include <QLabel> #include <QLineEdit> #include < Qprogressbar> //control showing progress bar # include <QComboBox> #include <QPushButton> #include <QGridLayout> //Grid layout class Progressdlg:public qdialog{ q_objectpublic: progressdlg (Qwidget *parent = 0); ~progressdlg (); Define slot function private slots: void Startprogress (); Define the control private: Qlabel *filenum; Indicates the amount of the document Qlineedit *filenumlineedit; Qlabel *progresstype; Qcombobox *combobox; Qprogressbar *progressbar; Qpushbutton *startbtn; Qgridlayout *mainlayout;}; #endif//Progressdlg_h
Progressdlg.cpp
/*** Book: "QT5 Development and examples" * function: Complete the definition of the display of the interface * file: progressdlg.cpp* time: January 2, 2015 15:27:37* Author: cutter_point*/#include " Progressdlg.h "#include <QProgressDialog>//The Progress box for the slow process of displaying the progress bar # include <QFont> #include <iostream> using namespace Std; Progressdlg::P Rogressdlg (Qwidget *parent): Qdialog (parent) {//Finish initialization of Interface Qfont font ("Arial", 12); SetFont (font); Setwindowtitle (tr ("Progress")); FileNum = new Qlabel; Filenum->settext (TR ("The file num")); Number of files Filenumlineedit = new Qlineedit; Filenumlineedit->settext (tr ("100000")); Default value Progresstype = new Qlabel; Progresstype->settext (TR ("The Show Type"); Type of display ComboBox = new Qcombobox; Combobox->additem (tr ("ProgressBar")); The first display mode is Combobox->additem (tr ("ProgressDialog")); The second mode of display ProgressBar = new Qprogressbar; Progressbar->setformat ("%p%"); Show startbtn = new Qpushbutton as percent complete; Startbtn->settext (tr ("Begin")); Start//cout<< "??? 3333 "<<endl; Mainlayout = new Qgridlayout (tHis); Grid Layout//cout<< "??? 3333____????? 11111 "<<endl; Mainlayout->addwidget (filenum, 0, 0); Mainlayout->addwidget (filenumlineedit, 0, 1);//cout<< "??? 33333__????? 1111111___??? 222222 "<<endl; Mainlayout->addwidget (Progresstype, 1, 0);//cout<< "??? 3333____?????? 22222 "<<endl; Mainlayout->addwidget (ComboBox, 1, 1); Mainlayout->addwidget (ProgressBar, 2, 0, 1, 2); Mainlayout->addwidget (STARTBTN, 3, 1);//cout<< "??? 3333____111111111 "<<endl; Mainlayout->setmargin (15); Set the interval size mainlayout->setspacing;//cout<< "??? 4444 "<<endl; Connect to connect (startbtn, SIGNAL (clicked ()), this, SLOT (Startprogress ()));} The specific work of the progress bar shows the slot function void Progressdlg::startprogress () {bool OK; int num = Filenumlineedit->text (). ToInt (&ok); Convert text to int type value if (combobox->currentindex () = = 0)//If you select the first one then ProgressBar mode {progressbar->setrange (0, NUM); Set range, Min and Max values for (int i = 1; I <= num;++i) {progressbar->setvalue (i); Set the current value cout<<i<<endl; }} else if (combobox->currentindex () = = 1)//If you select the second display mode, ProgressDialog {qprogressdialog *progr Essdialog = new Qprogressdialog (this); Qfont Font ("Song Body", 12); Progressdialog->setfont (font); Progressdialog->setwindowmodality (Qt::windowmodal); Display in a simulated manner, that is, while the progress is displayed, other windows will not respond to the input signal progressdialog->setminimumduration (5000); Set the wait time shown by the progress bar, 5 Seconds progressdialog->setwindowtitle (tr ("Please Wait")); Sets the display time of the caption Progressdialog->setlabeltext (tr ("Copying ...")); Progressdialog->setcancelbuttontext (tr ("Cancel")); Exit button name Progressdialog->setrange (0, num); Set the displayed range for (int i = 1; I <= num; ++i) {progressdialog->setvalue (i); Set the current value//cout<<i<<endl; If the button cancel is detected to be activated, jump out if (progressdialog->wascancEled ()) return; }}}progressdlg::~progressdlg () {}
Main.cpp
#include "progressdlg.h" #include <qapplication>int main (int argc, char *argv[]) { qapplication A (argc, argv); Progressdlg W; W.show (); return a.exec ();}
OK, just for everyone to have a good cool!!
Make you happy, make you laugh
I'll go. Project upload, next time to connect it
Connection: To know the funeral, and listen to tell.
"QT5 Development and examples" 10, about the progress bar display