PDA

View Full Version : Linear analog display



CoderMan
26th February 2012, 21:09
Yo!

I'm trying to make a one-dimensional horizontal indicator that has a background color and on top of that a colored field whose width changes based on input: at 0% only background is seen, at 20% the leftmost fifth is colored with the foreground color and at 100% only foreground color is seen.

I tried to go with two labels but I'm having trouble getting them to align right on top of each other in a layout. Any ideas?

An additional difficulty: the width of this entire control is subject to change. How do I recompute the overlay size while avoiding infinite recursion in a resize event? I suspect layouts will not help here, since they will start shrinking the background label before starting to shrink the (smaller) overlay, distorting the displayed value.

Thanks in advance, I really could use help on this one.

wysota
26th February 2012, 22:01
QProgressBar

CoderMan
27th February 2012, 19:39
I did consider QProgressBar, but I was sceptical it could really be reliably styled to such a degree that it becomes as minimalistic as I described, on all/most platforms and themes. But apparently it can.

I suspect I will need a way to synchronize the relative widths of two widgets regardless... although I suppose I could take a look at QProgressBar's source code.

wysota
27th February 2012, 20:30
You can always subclass it and provide your own painting by reimplementing paintEvent().