PDA

View Full Version : How can we paint image on slider?



pratik041
9th November 2011, 07:43
I want to paint image on slider groove and slider handle individually.

wysota
9th November 2011, 08:47
I'm assuming your question is "where do I start". Basically you have two choices, to subclass the slider and reimplemnt thebpaint event to draw something ON the groove or implement a subclass of QStyle to draw something INSTEAD of the groove.

pratik041
9th November 2011, 08:51
but if i will re implement the paint event can i paint groove and handle each with different image.

wysota
9th November 2011, 10:29
If you reimplement the paint event, you can paint whatever you want. You can even not paint at all. Also consider using stylesheets instead of reimplementing the event.

pratik041
9th November 2011, 10:54
stylesheet i have tried but it is not as flexible as i want.Can you please tell me how i will paint on the handle of the slider. what position i will give suppose if i am using the following code

void custom_slider::paintEvent (QPaintEvent *ev)
{
QPainter painter(this);
painter.drawPixmap (QRectF(?,?,94,17), pixmap,QRectF(0,0,94,17));
painter.drawPixmap (QRectF(?,?,7,7),pixmap1,QRectF(0,0,7,7));

}

where pixmap is the image for groove.
pixmap1 for handle of slider.

wysota
9th November 2011, 18:17
It's not that easy. You need to calculate those positions. However it will probably be simpler to implement it in QProxyStyle subclass.