[SOLVED] Speedometer Needle
I am new to Qt and facing the following issue. I have been given a background image of a tachometer/speedometer which I can load onto my Main Window widget.
Now I would simply like to add a Needle to this device right in the middle, which would be a dynamical object able to respond to updates. Is there any Widget which would allow me to achieve this?
We cannot use QML. We need to obtain this result by using a widget class.
In case a predefined QNeedle does not exist, How would I start creating such a graphical object?
Many Thanks for your help
there is no widget available which does what you want out of the box.
You can subclass QWidget and overrride it's paintEvent() handler and do all the drawing in there.
E.g. draw the background image first and then the needle by yourself. You can use all the capabilities of the QPainter class for drawing.
Or you just go with the QGraphicsView approach and add the background image and also the needle (as image) as QGraphicsPixmapItems and just rotate the needle-item accordingly.
Alternatively you can also use one of "Qwt's widgets":http://qwt.sourceforge.net/controlscreenshots.html.
Or check the source code of their implementation...
A while ago Nokia showcased some nice gauge widgets:
For now your first solution of subclassing QWidget and overriding paintEvent() seems to work. Hopefully it won't take too much work to paint a reasonable dial or gauge control. Qwt's widgets look quite tempting though.