Subclassing QSlider with handle as a Widget
-
Ok, what events do you need ?
Isn't the default "signals":http://qt-project.org/doc/qt-5/qabstractslider.html#signals what you need ? -
These events are enough yes, but I need them on the slider's handle, not on the slider itself ;)
-
bq. I need them on the slider’s handle
Which one exactly ?
Basically you can subclass slider, obtain a rect of the handle style()->subControlRect and from here you can filter all mouse events from handle only. For paint of course you can reimplement paintEvent, but with style sheet is easily. What other events do you need ? -
I need these ones on the handle:
virtual void mouseDoubleClickEvent(QMouseEvent * event)
virtual void mouseMoveEvent(QMouseEvent * event)
virtual void mousePressEvent(QMouseEvent * event)
virtual void mouseReleaseEvent(QMouseEvent * event)
virtual void moveEvent(QMoveEvent * event)If I understand you, you want to "render" the CustomWidget without embedding it to the handle and filter the events on the rectangle zone and not on the customwidget?
-
Yes you can reimplement all of these events in QSlider subclass, and filter all mouse events for handle rect only. Thats all ...
@
if (style()->subControlRect(etc).contains(event->pos())
@ -
ok :)
And for painting the customwidget, you just instantiate it into the paint method of the subclasses slider and parent it to the subclassed slider?
-
In my example with yes, but I needed three handles not one. With only one handle you can use QSlider signals, events and style(sheets) without any other additional widget(s)
-
And how to you render the customWidget with stylesheet?
-
I'm not using stylesheet in example posted. The default slider handle is rendering by application style and the other two are QLabels with image pixmap.
-
Yes it was as I thought. So how do I do ? :D
-
What's wrong by subclassing QSlider and reimplement all mouse events you need ? Also you can paint the slider handle either in paint event or using stylesheet. So you have a complete control on slider handle.
-
Hello again,
I didn't know we could render a widget with QPainter, I never did like that in the past.
You are talking about :painter->begin(mycustomwidget); right?
Looks like there is also itemChange if I forget about the idea of subclassing a QSlider ....
-
I think you misunderstood me ( or maybe I misunderstand you :-) )
Why do you need a "customwidget" at all ? Consider that your "customwidget" is slider handle. You can render this "handle" in the way you want, also you can intercept mouse events for slider and filter these for "handle" rect. -
Its probably me who misunderstood :D
I wanted a separated widget for architecture reasons, to make it modular.
Lets say that tomorrow I decide that it will not be a slider but something else.
Or I want to render this customwidget in another view in my software ...There are a lot of reasons :)