How to show an 'infinite floating' progres

2019-02-16 08:32发布

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?

标签: c++ qt qt4
3条回答
We Are One
2楼-- · 2019-02-16 09:04

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.

查看更多
Lonely孤独者°
3楼-- · 2019-02-16 09:18

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);
查看更多
Evening l夕情丶
4楼-- · 2019-02-16 09:23

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

查看更多
登录 后发表回答