Search code examples
c++qtqt4

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


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?


Solution

  • 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).