Nominate our 2022 Qt Champions!

QProgressBar and stylesheet: best way to add a vertical bar

  • I would like to display a treshold value in my progressbar:

    I already style QProgressBar and QProgressBar::chunk to color my bar and background with nice gradients, and now I want to add this vertical line. What's the smartest way to do this?
    Ideally I would like to have this treshold displayed on top of the chunk.
    Should I play with background-image or another tag?

  • One possibility is to use a custom progress bar class, overwrite paint event, call default painting for the styling and draw the threshold value afterwards on top.

    Background image would be behind the chunk :-(

  • I finally took a few minutes to subclass my progressbar.
    I added a QRubberBand to handle a min and max threshold (for hysteresis). Works great for little to no efforts!

    I am now wondering if I can set a styleSheet on a QRubberBand to alter color and opacity!

Log in to reply