11

Has anyone any suggestions on how to align the status text on the QProgressBar in Qt? By default in Windows it appears to the right of the bar but I'd prefer to place it either above the bar or within the bar itself without having to extend the object and implement a status label myself.

Screenshot below:

enter image description here

Community
  • 1
  • 1
kh25
  • 1,238
  • 1
  • 15
  • 33
  • 1
    Can you show the code how you actually added the text to the right of the progress bar? By default, `QProgressBar` only shows the percentage of the progress, and this is a read-only property which can be retrieved with `QProgressBar.text()`, but not modified – Andreas Fester Feb 22 '13 at 10:05
  • 1
    No problem Andreas here's the code: barProgress_->setFormat("Downloading Training Console 1..."); – kh25 Feb 22 '13 at 10:12

3 Answers3

20

Yet another approach would be to set the alignment of the status text through QProgressBar::setAlignment:

barProgress_->setAlignment(Qt::AlignCenter);

Progress bar screen shot

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
2

You can use stylesheets to modify the look of the progress bar. Here's an example: http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qprogressbar

vipw
  • 7,593
  • 4
  • 25
  • 48
0

Thanks to vipw's suggestion above I have achieved the effect I'm looking for with a simple call to setStyleSheet() as follows (there is no spreadsheet currently defined for this app and it's practically finished so the call to this method will save me having to include an entire new css file):

barProgress_->setStyleSheet(QString::fromUtf8("text-align: center;"));

The result is:

enter image description here

Anyway thanks for the help.

kh25
  • 1,238
  • 1
  • 15
  • 33