The QT progress bar Operation example is this article to introduce the content, in QT can use Qprogressbar or the Qprogressdialog to realize the progress bar.
Use of Qprogressbar
First drag a button and a progress bar widget in the designer and initialize it as follows
Ui->progressbar->setrange (0,50000-1); Ui->progressbar->setvalue (0);
Event handling for the button:
void mainwindow::on_pushbutton_clicked () {for (int. i=0;i<50000;i++) {for (int j=0;j<20000;j++); Ui->progressbar->setvalue (i); } }
This will show the progress bar, which calculates the percentage automatically and shows
How to use Qprogressdialog
The use of Qprocessdialog is similar, except that it is displayed as a dialog box, and it also provides a Cancel button to cancel the operation. Qprocessdialog will automatically calculate that percentage and display it.
void mainwindow::on_pushbutton_clicked () {Qprogressdialog process (this); Process.setlabeltext (TR ("Processing ...")); Process.setrange (0,50000); Process.setmodal (TRUE); Process.setcancelbuttontext (tr ("Cancel")); for (int i=0;i<50000;i++) {for (int j=0;j<20000;j++); Process.setvalue (i); if (process.wascanceled ()) break; } }
Summary: QT progress bar Operation Examples of the contents of the introduction, I hope this article is helpful to you.