Progress bar of QT Development QT Control

Source: Internet
Author: User

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.

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.