Changing the QProgressBar Color in Windows
-
I have a QProgressBar showing the content of a tank and when its content decreases I want have another color on the progressbar. I've tried the following code, but without success:
QPalette p = ui->progressBar->palette(); QColor color = Qt::red; p.setBrush(QPalette::Highlight, QBrush(color)); ui->progressBar->setPalette(p);
I've found the hint in the internet to use the QProxyStyle class, but I have no further explanation:
https://stackoverflow.com/questions/56558606/qprogressbar-change-color-while-keeping-os-style
-
Hi
That would be CE_ProgressBarContents and also PE_IndicatorProgressChunk
https://code.woboq.org/qt5/qtbase/src/widgets/styles/qcommonstyle.cpp.html#1549
However, each platform QStyle might do differently
and no matter what I did, it would not change the green color on Windows.So outside of reimplementing custom drawing for the "fill" im not sure how to change the color with a proxy.
It is possible via stylesheet though
https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qprogressbar -
Dear mrjj thank you for your help which gave me some ideas, finally I've found this here:
https://forum.qt.io/topic/53447/solved-changing-progress-indicator-in-qprogressbar
which helped me to get a better than excepted result