From 2c762f3b8b284a7c6dc0c499b7052013bad5b707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Fri, 17 Apr 2009 18:59:17 +0200 Subject: Make sure tooltips are shown properly in popups. The problem was that if you had child widgets of a popup, only child widgets that had hasMouseTracking() == true received the ToolTip event. This was because in order for a widget to receive a ToolTip, it relied on the MouseMove event. It still relies on the MouseMove event, but the problem with the previous code was that it did not even *try* to deliver the MouseMove event to the widget that did not have mousetracking. And it was the code that "tried" to deliver (QApplication::notify()) the event that also was responsible of finding which widget it should get the tooltip from. Unfortunately the previous code did not even enter QApplication::notify() because of that early cut-off. The result was that the event was propagated up to the parent widget (which was the popup) and consumed by the popup. (Nothing would happen unless the popup itself had a tooltip). This is also how translateMouseEvent() is implemented in qapplication_x11.cpp. --- src/gui/kernel/qapplication_win.cpp | 5 +---- tests/auto/qwidget/tst_qwidget.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index fae0335..2f2fc2c 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -3164,10 +3164,7 @@ bool QETWidget::translateMouseEvent(const MSG &msg) if (popupButtonFocus) { target = popupButtonFocus; } else if (popupChild) { - // forward mouse events to the popup child. mouse move events - // are only forwarded to popup children that enable mouse tracking. - if (type != QEvent::MouseMove || popupChild->hasMouseTracking()) - target = popupChild; + target = popupChild; } pos = target->mapFromGlobal(globalPos); diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index a557563..9547c8f 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -5787,6 +5787,35 @@ void tst_QWidget::setToolTip() widget.setToolTip(QString()); QCOMPARE(widget.toolTip(), QString()); QCOMPARE(spy.count(), 2); + + + + for (int pass = 0; pass < 2; ++pass) { + QWidget *popup = new QWidget(0, Qt::Popup); + popup->resize(150, 50); + QFrame *frame = new QFrame(popup); + frame->setGeometry(0, 0, 50, 50); + frame->setFrameStyle(QFrame::Box | QFrame::Plain); + EventSpy spy1(frame, QEvent::ToolTip); + EventSpy spy2(popup, QEvent::ToolTip); + frame->setMouseTracking(pass == 0 ? false : true); + frame->setToolTip(QLatin1String("TOOLTIP FRAME")); + popup->setToolTip(QLatin1String("TOOLTIP POPUP")); + popup->show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(popup); +#endif + QTest::qWait(100); + QTest::mouseMove(frame); + QTest::qWait(900); // delay is 700 + + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 0); + if (pass == 0) + QTest::qWait(2200); // delay is 2000 + QTest::mouseMove(popup); + delete popup; + } } void tst_QWidget::testWindowIconChangeEventPropagation() -- cgit v0.12