Use of progress bar in QT

Source: Internet
Author: User

In Qt, you can use Qprogressbar or Qprogressdialog to achieve a progress bar.

Use of Qprogressbar

First drag a button and a progress bar widget in the designer and initialize it as follows

Add: The following two sentences are written in the MainWindow constructor.

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


Transferred from:http://blog.sina.com.cn/s/blog_6151770b0100ndle.html
You can only turn!

Use of progress bar in QT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.