Unsolved how to draw a custom slider which can be moved by mouse as the Qt intrinsic slider?
-
how to draw a custom slider which can be moved by mouse as the Qt intrinsic slider?
i already use QPainter draw some additional effect on the slider-bar. -
Is it repeat of the question ?
As explained earlier, you need to draw things on your own using the paintEvent(..) & handle the mouse events appropriately. Please look at the topics how to write customWidgets.
-
yes.
i used QGraphicsView before.
but this time seems no need to use QGraphicsView, and now i am wondering how to draw the slider and how to move it by the mouse
thank you very much -
You can do it in graphics view also. Again I'm repeating the following steps.
- Look at how custom widgets are created.
- re-impliment the paintEvent(...) function.
- Draw slider, handler, bar everything on your own.
- re-implement mousePress, mouseRelease events.
Look at the examples I have sent earlier. You are asking the code of the custom slider which you wanted. This will will be very difficult. Here people will help you with specific problem.
-
ok,i just wonder if not use QGraphicsView, just use the QPainter, is it more simple and easy?
and can u simply give a hint to to move the slider by the mouse while not use QGraphicsView? check the mouse pos in the slider-rect? -
- Draw your slider handle in side the paintEvent(..) function.
- Handle mouse press, release and move function.
- Change the x, y position of your handle inside the mouse event handlers.
- Call paintEvent(...) again by calling update(..)
Look at the pathStroke example. It may help you.
-
Hi
Just as a note.
QtCreator comes with something like the gradient thing.
You could look around its code to see how its done.