Fix wrong position in wxMouseEvent generated by sub-window

Use screen coordinates, as the window coordinates in QMouseEvent may be
relative to a different window.

Closes https://github.com/wxWidgets/wxWidgets/pull/1351
This commit is contained in:
Matthew Griffin
2019-06-12 15:04:48 +01:00
committed by Vadim Zeitlin
parent 35de675830
commit 71ad73fdbe

View File

@@ -1456,11 +1456,15 @@ bool wxWindowQt::QtHandleMouseEvent ( QWidget *handler, QMouseEvent *event )
} }
// Fill the event // Fill the event
QPoint mousePos = event->pos();
// Use screen position as the event might originate from a different
// Qt window than this one.
wxPoint mousePos = ScreenToClient(wxQtConvertPoint(event->globalPos()));
wxMouseEvent e( wxType ); wxMouseEvent e( wxType );
e.SetEventObject(this); e.SetEventObject(this);
e.m_clickCount = -1; e.m_clickCount = -1;
e.SetPosition( wxQtConvertPoint( mousePos ) ); e.SetPosition(mousePos);
// Mouse buttons // Mouse buttons
wxQtFillMouseButtons( event->buttons(), &e ); wxQtFillMouseButtons( event->buttons(), &e );
@@ -1472,8 +1476,8 @@ bool wxWindowQt::QtHandleMouseEvent ( QWidget *handler, QMouseEvent *event )
// Determine if mouse is inside the widget // Determine if mouse is inside the widget
bool mouseInside = true; bool mouseInside = true;
if ( mousePos.x() < 0 || mousePos.x() > handler->width() || if ( mousePos.x < 0 || mousePos.x > handler->width() ||
mousePos.y() < 0 || mousePos.y() > handler->height() ) mousePos.y < 0 || mousePos.y > handler->height() )
mouseInside = false; mouseInside = false;
if ( e.GetEventType() == wxEVT_MOTION ) if ( e.GetEventType() == wxEVT_MOTION )