From c418f5ce8d11f318126aec03385011c919916d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 4 May 2011 10:42:54 +0200 Subject: [PATCH] Proper sub-widget mouse grabbing in QWidgetWindow. --- src/gui/kernel/qwidgetwindow_qpa.cpp | 8 +++++++- src/gui/kernel/qwidgetwindow_qpa_p.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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