Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show an 'infinite floating' progressbar in Qt without knowing the percentage?

Tags:

c++

qt

qt4

I tried to show a progressbar during some operation. However, I don't know how many times it will takes so that the percentage can't be calculated. It seems that Windows has a progressbar style like this: infinite floating progressbar I tried to implement this style by setting both maximum and minimum to 0:

ui->progressBar->setMaximum(0);

ui->progressBar->setMinimum(0);

It seems that I did it, except the fact that it really won't stop until the program exits, despite that I called reset() function trying to stop it.

So my question is how to implement this kind of progressbar correctly?

like image 604
user957121 Avatar asked Aug 01 '12 07:08

user957121


3 Answers

You need to set the minimum, maximum and current values :

ui->progressBar->setMaximum(0);
ui->progressBar->setMinimum(0);
ui->progressBar->setValue(0);

QProgressBar'a details description tells :

If minimum and maximum both are set to 0, the bar shows a busy indicator instead of a percentage of steps.

It must be some kind of a bug you encountered. Wouldn't be the first in Qt.

like image 165
BЈовић Avatar answered Sep 27 '22 23:09

BЈовић


When the operation completes, try setting an arbitrary maximum value and set the progress value to the same number:

ui->progressBar->setMaximum(100);
ui->progressBar->setValue(100);

This way, the progress bar should fill up to indicate completion (which is a handy visual cue, since your operation actually has completed).

like image 35
Frédéric Hamidi Avatar answered Sep 28 '22 00:09

Frédéric Hamidi


I have upvoted BЈовић's solution, since he pointed to cite from official documentation, but unfortunately, this mechanism was not working for me (can't figure out what was the reason). This is the way I've solved it (according to documentation, QProgressBar::setRange -- The QProgressBar can be set to undetermined state by using setRange(0, 0)):

ui->progressBar->setRange(0, 0);
like image 38
tro Avatar answered Sep 28 '22 01:09

tro