No percentage label on QProgressBar when switching to vertical
-
I need to have a QProgressBar that is vertically aligned to show the visually the content of a solution container. When I align the QProgressBar horizontally I have the label visible that shows the percentage, when I align the QProgressBar vertically the label with the percentage is not visible anymore.
-
Hi and welcome to devnet,
What version of Qt ?
On what platform ?Please provide a minimal compilable example that shows the behaviour.
-
Look like this is still this old unresolved bug:
The problem is the same in Windows and Linux, here the screenshot of a widget with a horizontal and a vertical QProgressBar with the same settings (except the orientation):

Here the code of the *.ui file:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>373</width> <height>465</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralwidget"> <layout class="QGridLayout" name="gridLayout_2"> <item row="0" column="0"> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="QProgressBar" name="progressBar"> <property name="value"> <number>24</number> </property> </widget> </item> <item row="0" column="1"> <widget class="QProgressBar" name="progressBar_2"> <property name="value"> <number>24</number> </property> <property name="orientation"> <enum>Qt::Vertical</enum> </property> </widget> </item> </layout> </item> </layout> </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>373</width> <height>30</height> </rect> </property> </widget> <widget class="QStatusBar" name="statusbar"/> </widget> <resources/> <connections/> </ui>
-
Hi
Seems like the bug is still around
Win 10. Qt 5.14.1 -
Since you have them, would either of you please update that report with a minimal compilable example ?
-
Hi
A fix could be using a QProxyStyle
(fast made, give it more love if used for real)
set with
ui->progressBar->setStyle( new Progressproxy );class Progressproxy : public QProxyStyle { public: Progressproxy() : QProxyStyle() {} public: virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const override { if (element == CE_ProgressBarLabel) { const QStyleOptionProgressBar *real = qstyleoption_cast<const QStyleOptionProgressBar *>(opt); // check real is not null... QStyleOptionProgressBar pb = *real; pb.rect = QRect(0, 0, w->width(), w->height()); proxy()->drawItemText(p, pb.rect, Qt::AlignCenter, pb.palette, pb.state & State_Enabled, pb.text, QPalette::Text); return; } QProxyStyle::drawControl(element, opt, p, w); } };
But to have it reserve space in the button of the bar like on horizontal, it seems one has to handle
all CE_ProgressBarXXX elements and reduce the rect (clientArea)
as the space used for the text seems not included when vertical.
(it uses the full widget area)
-
@hkottmann
Hi
Well, that sounds good as i was not sure having the value center would be ok since its normally at the end,
and if you can tweak it for something you wanted, its a win.
Also, its a small hack and while i didn't test it, it should also respond
as expected on other properties (like disabled etc) since im
using the normal draw functions.