11

I have a QProgressBar instance in marquee mode (maximum = minimum = 0).

I would now like to add some text over the progress bar like "Loading..."

The documentation says:

Note that whether or not the text is drawn is dependent on the style. Currently CDE, CleanLooks, Motif, and Plastique draw the text. Mac, Windows and WindowsXP style do not.

What should I do?

This is the code I'm using (not working as text isn't visible at all):

progressBar.setVisible(true);
progressBar.setMaximum(0);
progressBar.setMinimum(0);
progressBar.setTextVisible(true);
progressBar.setFormat("Loading...");
progressBar.setAlignment(Qt::AlignCenter);

3 Answers 3

11

As you want to add text over Progress bar, you need to align the Text as it is by default on right hand side. Below code template will work for you, considering progressBar your instance.

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

enter image description here

It works well for me.The widget left bottom is a progressbar.I think you shouldn't set that (maximum = minimum = 0)

1

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

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

About the style type, you will have to see which one do you want or need and pick it. Take a look to QStyleOptionProgressbar

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.