PDA

View Full Version : Rotating a slider...



ACFred
23rd February 2008, 22:15
Hi there.
I've never used Qt before, but am about ready to jump in for a project at work.
On thing we're looking for is a slider widget that we can rotate 45 degrees.
Is something like that possible? If so, what would be the best way to go about it?

Thanks,

Alec

wysota
24th February 2008, 00:35
You can't have it out of the box. You'd have to subclass the slider and reimplement its event handlers (at least paint, mousePress, mouseMove and mouseRelease). In the reimplementation you'd have to recalculate cursor positions and call the base class handlers with the modified events.

Gopala Krishna
24th February 2008, 03:08
Hi there.
I've never used Qt before, but am about ready to jump in for a project at work.
On thing we're looking for is a slider widget that we can rotate 45 degrees.
Is something like that possible? If so, what would be the best way to go about it?

Thanks,

Alec

If you can use qt-4.4 , you can probably try QGraphicsWidget class to embed a slider in QGraphicsView as a QGraphicsItem. This allows you to have anykind of transformation on your slider.
Have a look at
http://labs.trolltech.com/blogs/2007/11/22/widgets-on-the-canvas-integrated/

wysota
24th February 2008, 10:37
Currently I managed to do something like this using the approach I suggested. It's not perfect - not all events are propagated by my proxy to the slider and vice versa.

Gopala Krishna
24th February 2008, 13:02
Did you reimplement the slider and paint the rotated one using QWidget::render() ? Or are you using QStyle to draw the controls ?

wysota
24th February 2008, 13:19
Did you reimplement the slider and paint the rotated one using QWidget::render() ? Or are you using QStyle to draw the controls ?

I didn't touch the slider. I implemented a proxy widget for transforming other widgets similar to the widget proxy from the graphics view that allows arbitrary transformations of widgets.

Gopala Krishna
24th February 2008, 15:36
Ok nice approach. Is the widget's geometry still rectangular(globally) after rotating the hosted widget ?
Have you done masking also ?

wysota
24th February 2008, 15:56
Is the widget's geometry still rectangular(globally) after rotating the hosted widget ?
Yes.

Have you done masking also ?
No, there is no need for that - widgets are transparent by default, so no masking is needed for transparency and if you want a non-rectangular widget, you have to do the same as for other widgets - mask them yourself (all widgets are rectangular by default). Masking is expensive, so it's better to avoid it if possible.