Mouse click event has a displacement in a QOpenGLWidget
Hi, I have an application that allows the user to click over some points and It returns its color. The problem is that when I click over a point, the coordinates that the mouse event returns are a bit moved and It returns the color of the background instead.
I have a class that inhetirs from QOpenGlWidget that implements this Mouse event and this Widget is set in a UI with some buttons. Here you have an image:
If I click some pixels around the point, it returns the right color of the point, so I think that the click is returning a position with is not exactly in my QOpenGlWindow, it has some displacement
Here I show you what is happening:
I click over a point and it returns white color:
Then, I click over one point of the background near the point and it returns the color of the point. Note that this only happens in that right point, not all the points around my point.
I think that the mouse event is returning a point considering also the margins of the window, not only the window. Any ideas?.
I've just tried it but I get the same trouble. Once I get the x and y values, I do glReadPixels to check the colour under this position. When the cursor is near the margins of the window I get the colour of the margins instead of white.
It occurs the same on top, left and right margins.
I am using a layout to place the qopenglwidget on the ui.
Where do you catch the mouse event?
@Christian-Ehrlicher in glwindow which is the class that inherits from QOpenGLWidget and creates the window.
bool glwindow::eventFilter(QObject *obj, QEvent *event)
and in my interface class I do this:
QSurfaceFormat format; format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setVersion(4, 1); format.setProfile(QSurfaceFormat::CoreProfile); QSurfaceFormat::setDefaultFormat(format); glwindow *ventana = new glwindow(); ventana->setFormat(format); ventana->show(); std::cout<<"Ventana lanzada"<<std::endl; ventana->setMouseTracking(true); ventana->installEventFilter(ventana); ventana->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Expanding); this->ventana = ventana; ui->gridLayout->addWidget(ventana,0,0);
I'm not sure but do the corrdinates match to the main windgets coordinates? Did you check by e.g. overwriting mouseMoveEvent() on the main window?
JesusM last edited by JesusM
@Christian-Ehrlicher mouseMoveEvent is a QWidget function, so what do you mean, the openGLWidget or the main window where the widget is placed?