PDA

View Full Version : QSlider - how to color the space



newb
20th July 2010, 09:12
Dear developers...

i need to design my QSlider ...

I have start point and end point on the slider bar

the start point and the end point is movable by the user

now i need to color the space between the start point and the end point

Please let me know your helps and suggestion on this

tbscope
20th July 2010, 09:16
Is your question on how to color the space?

newb
20th July 2010, 09:19
. ..

tbscope
20th July 2010, 09:23
This is highly theme specific as the look of the slider can change a lot between styles.

However, the easiest way to do this outside of theming is to subclass the QSlider and reimplement the paint function. Draw the slider first, then on top of that draw a rectangle of custom size with custom color.

Edit, but you'll loose the slider handle behind that rectangle.
Maybe it's better to paint it underneath the slider.

Anyway, the best way to do this is in the style itself or create a slider from scratch (reimplement the complete paint function)

newb
20th July 2010, 09:27
thank you for the reply...if i try using with styles how can i go with...

tbscope
20th July 2010, 09:32
I guess you have a custom widget (a subclassed QSlider) ?

If so, create a QStyle subclass based on the style you normally use. Then implement the painting of your custom widget, based on a regular QSlider.
But, before you paint the items that need to be on top (like the slider handle) and after you paint the items that need to be underneath, paint the colored space.

Something like this:
1. paint the borders and background
2. paint the colored space
3. paint the handle

Step 2 would be missing in a regular QSlider.
If you just reimplement the paint function like I said earlier, you can't paint in the middle, only at the beginning (underneath) or at the end (on top)

dpatel
20th July 2010, 09:51
Just skimming through you quesiton I am wondering if you could use stylesheet.
More info @ QSlider Stylesheet (http://doc.trolltech.com/4.6/stylesheet-examples.html#customizing-qslider)