Qt QProgressBar - aligning text
Asked Answered
A

3

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

Armanda answered 21/2, 2013 at 17:59 Comment(2)
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 modifiedWeighbridge
No problem Andreas here's the code: barProgress_->setFormat("Downloading Training Console 1...");Armanda
W
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

Weighbridge answered 22/2, 2013 at 10:57 Comment(1)
I think this is possibly the nicest solution so am marking as such.Armanda
J
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

Jabon answered 22/2, 2013 at 9:58 Comment(0)
A
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.

Armanda answered 22/2, 2013 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.