Display coordinate information whenever cursor is hovered over a primitive object.
-
I have rendered a OpenGL ES(2.0) triangle using QGLWidget and QGLFunctiions. So if I hover the mouse cursor over rendered scene it should show respective (x,y) coordinates on the screen.How can I achieve this.Is it possible using Qt?
I heard about QHoverEvent but not sure how it can be useful. please suggest. -
Hi,
Events are a mechanism of QObject: your OpenGL context can't detect you're hovering a drawn primitive. Nevertheless you can track your cursor inside your widget -- just activate "mouse tracking":http://qt-project.org/doc/qt-5/qwidget.html#mouseTracking-prop on it and handle events by reimplementing QGLWidget::mouseMoveEvent() -- an then detect the primitive hovered with OpenGL picking. Show the coordinates on the screen using "QGLWidget::renderText()":http://qt-project.org/doc/qt-5/qglwidget.html#renderText.