Unsolved QGLWidget mouse movement tracking
-
is there code/tutorial on how to track mouse movement within QGLwidget display for OppenGL stuff? for example if my display size is 300,300, i like to show my mouse position x,y when the mouse is within the GUI display screen
-
-
@s002wjh I recommend using
QOpenGLWidget
instead.QGLWidget
is deprecated. -
ok thanks. i assume QT mousePressEvent or mousemoveevent function can be used in QTopenGLwidget class.
also using mouseevent, if i click the button, how do i display the x,y at the pointer of my mouse.
is there mouseClickEvent?
-
Hi
yes, QOpenGLWidget is also a QWidget and offer same virtual functions to override.
mouseClickEvent = mousePressEvent.- also using mouseevent, if i click the button, how do i display the x,y at the pointer of my mouse.
Do you mean the mouse position over the button
or do you mean the global mouse position at that moment ?
Note there is also
QPoint globalCursorPos = QCursor::pos();
to ask where mouse is in global coordinates.
You can call that from any function and no need for subclassing.
In mousePress, the pos you get there is translated to the local coordinates system.
Very useful if you want to draw on the widget etc.So it really depends on what you really want to archive ?
-
hi i like to display text of X,Y coordinate when my mouse is clicked within the GUI.
for example if my mouse arrow position currently is x=5, y=6. i like to settext so it dispaly 5,6 at coordinate 5,6.
such as
-
@s002wjh
Ok, in that case you want the local coordinates and mousePress is the way to go. -
@mrjj
yes i got that but do i use qlabel, setText and setposition and setfont to display the coordinate or there are better way to do it. -
@s002wjh
Hi
It really depends on what you already have.
If you draw the graphs looking thing in the image, you could also just
store the values in variables and draw it as part of the graphs.
Else a Label is not super bad but might not be optimal if you say resize the window etc as
the labels stay in same position. -
@mrjj
so i do have the location of mouse stored using mouseevent, but not sure best way to draw that text since its QGLwidget.
so maybe something like Qpainter drawtext? -
Hi
yeah something like
https://het.as.utexas.edu/HET/Software/html/opengl-overpainting.htmlBut i do wonder. how do you draw that graph look ? is that openGL?
-
@mrjj
yes its openGL stuff, i didn't wrote the code, all the stuff i done is use the qpainter. so not sure even qpainter would work. -
@s002wjh
Well you can use QPainter as links shows.
Its 4.8 and the older openGL widget but should work the same in later classes.