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:
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?
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).
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.
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);