QT text: QProgressBar

I have an instance of QProgressBar in selection mode (maximum = minimum = 0).

Now I would like to add text above the progress bar, for example, "Loading ..."

The documentation says:

Please note that regardless of whether the text is drawn, it depends on the style. CDE, CleanLooks, Motif, and Plastique are currently drawing text. Mac, Windows and WindowsXP do not.

What should I do?

This is the code I'm using (doesn't work, as the text doesn't display at all):

progressBar.setVisible(true); progressBar.setMaximum(0); progressBar.setMinimum(0); progressBar.setTextVisible(true); progressBar.setFormat("Loading..."); progressBar.setAlignment(Qt::AlignCenter); 
+5
source share
3 answers

enter image description here

This works well for me. The widget at the bottom left is a progressbar. I think you should not set this (maximum = minimum = 0)

+3
source

As you want to add text over the progress bar, you need to align the text as it is by default on the right side. The below code template will work for you, given the progressBar your instance .

  progressBar->setTextVisible(true); progressBar->setFormat("Loading..."); progressBar->setAlignment(Qt::AlignCenter); // This will add text over Progress Bar 
+3
source

First you must set it visible: progBar->setTextVisible(true);

Then write the text using progBar->setFormat("Loading...");

Regarding the type of style, you will need to see which one you want or want, and select it. Take a look at the QStyleOptionProgressbar

0
source

All Articles