PDA

View Full Version : Bi-directional QProgressBar, drawn from the center?



cmb
9th May 2012, 21:32
Is it possible to configure the QProgressBar (or some similar widget) to display a bar that extends out from the center (rather than from one end)? For example, with a range from -100 to 100, I'd like a value of -50 to display a bar that extends from the midpoint, halfway to the left-hand side. A value of zero would display no bar at all.

Is there an existing control that would do this, or would it require a custom widget?

--Colin

Lykurg
9th May 2012, 21:55
I am not aware of such a widget. But you can simply subclass QProgressBar and overwrite the paint method. By using QStyledPainter or QStyle direct, you can even make the widget style aware.

cmb
12th May 2012, 20:17
What is the best way to draw the filled, rounded rectangle that is normally drawn by CE_ProgressBarContents? Do I need to use QStylePainter::drawRoundRect() and then somehow fill it to to match the style? (The style I normally use has light- and dark-blue stripes in the progress bar fill.)

Lykurg
12th May 2012, 21:46
the best way is to draw it with CE_ProgressBarContents! Use QStyle::drawControl() and just alter QStyleOption with the rectangle you want.