How To Change QProgressBar Chunk Color, While Retaining Shimmer Animation
-
Hello,
We notice the following animation play (before we've changed the style sheet) for a QProgressBar:
Note: Notice the whitish glow that passes over the QProgressBar.
However, after we've changed the chunk style sheet to another color (for example: red to denote an error):
myProgressBar.setStyleSheet("QProgressBar::chunk{background-color: rgb(255, 0, 0);}")
...we notice that the shimmer animation (that plays every couple of seconds) no longer plays:
Question: Is there a way to change the chunk color while continuing to play the shimmer animation?
Note: My OS is Windows 11 Professional.
Thank you,
Nelson -
Hi and welcome to devnet,
Qt stylesheet style does not use the native style hence the change of look.
One thing you can try is using the palette and change the highlight color. Note that it might not work as styles are free to ignore elements from the palette to conform to the OS. -
Hello SGaist,
Thank you for the prompt reply.
Unfortunately, it doesn't look like your solution works (likely meaning that this is simply not possible with Qt at the moment - if ever).
I tried the following:
progress_bar_palette = my_progress_bar.palette()
progress_bar_palette.setColor(QPalette.Highlight, QColor(Qt.red))
my_progress_bar.setPalette(progress_bar_palette)...but my progress bar remained green.
Thank you for at least trying to provide me with a solution.
Regards,
Nelson -
The other alternative is to write your own custom style (KDAB has an excellent article on why).
You can start with QProxyStyle and check the implementation of the windows related styles to see how the progress bar are painted and adapt that to your needs.