From a65157e5b7a2a1c2f018507f9d45f5b311cd387c Mon Sep 17 00:00:00 2001 From: Jian Liang Date: Wed, 6 Feb 2013 12:38:24 +0800 Subject: [PATCH] replay mouse press event after a popup widget has been closed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a popup widget(e.g. a popup menu) has been closed due to a mouse press event, the mouse press event will be consumed by the popup widget and the widget under the mouse pointer can't receive the event. This will lead to confusing behavior such as a push button under the mouse pointer is not been push down. This patch replay the mouse press event if a popup widget has been closed. Change-Id: Id493583dfea9e64ab2964e28d559122c43bbc2a6 Reviewed-by: Friedemann Kleint Reviewed-by: Gunnar Sletta Reviewed-by: Samuel Rødal --- src/widgets/kernel/qwidgetwindow.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 50b61beb05..d7b9d8c5fb 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -352,6 +352,21 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) && qt_replay_popup_mouse_event) { if (m_widget->windowType() != Qt::Popup) qt_button_down = 0; + if (event->type() == QEvent::MouseButtonPress) { + // the popup disappeared, replay the mouse press event + QWidget *w = QApplication::widgetAt(event->globalPos()); + if (w && !QApplicationPrivate::isBlockedByModal(w)) { + QWindow *win = w->windowHandle(); + if (!win) + win = w->nativeParentWidget()->windowHandle(); + if (win && win->geometry().contains(event->globalPos())) { + const QPoint localPos = win->mapFromGlobal(event->globalPos()); + QMouseEvent e(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers()); + e.setTimestamp(event->timestamp()); + QApplication::sendSpontaneousEvent(win, &e); + } + } + } qt_replay_popup_mouse_event = false; #ifndef QT_NO_CONTEXTMENU } else if (event->type() == QEvent::MouseButtonPress