Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT: QProgressBar display text

Tags:

qt

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);
like image 881
Stephen H. Anderson Avatar asked Jul 29 '15 14:07

Stephen H. Anderson


2 Answers

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 
like image 120
Amol Saindane Avatar answered Oct 06 '22 02:10

Amol Saindane


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)

like image 25
haris Avatar answered Oct 06 '22 02:10

haris