diff --git a/src/gui/kernel/qwidgetwindow_qpa.cpp b/src/gui/kernel/qwidgetwindow_qpa.cpp index fc49b30417..a58a03774e 100644 --- a/src/gui/kernel/qwidgetwindow_qpa.cpp +++ b/src/gui/kernel/qwidgetwindow_qpa.cpp @@ -91,13 +91,19 @@ bool QWidgetWindow::event(QEvent *event) void QWidgetWindow::handleMouseEvent(QMouseEvent *event) { // which child should have it? - QWidget *widget = m_widget->childAt(event->pos()); + QWidget *widget = m_implicit_mouse_grabber ? m_implicit_mouse_grabber.data() : m_widget->childAt(event->pos()); // TODO: make sure mouse release is delivered to same widget that got the press event if (!widget) widget = m_widget; + if (event->type() == QEvent::MouseButtonPress && !m_implicit_mouse_grabber) + m_implicit_mouse_grabber = widget; + + if (event->buttons() == Qt::NoButton) + m_implicit_mouse_grabber.clear(); + QPoint mapped = widget->mapFrom(m_widget, event->pos()); QMouseEvent translated(event->type(), mapped, event->globalPos(), event->button(), event->buttons(), event->modifiers()); diff --git a/src/gui/kernel/qwidgetwindow_qpa_p.h b/src/gui/kernel/qwidgetwindow_qpa_p.h index 9d577d17f3..7a3ff46e65 100644 --- a/src/gui/kernel/qwidgetwindow_qpa_p.h +++ b/src/gui/kernel/qwidgetwindow_qpa_p.h @@ -72,6 +72,7 @@ protected: private: QWidget *m_widget; + QWeakPointer m_implicit_mouse_grabber; }; QT_END_NAMESPACE