diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 7dcadf7..5d057ab 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1934,6 +1934,7 @@ void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::En
 
 void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
 {
+    qDebug() << Q_FUNC_INFO;
     if (!e->leave)
         return;
     if (e->leave.data()->d_func()->blockedByModalWindow) {
diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
index e4feda2..857059e 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -2063,6 +2063,7 @@ void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
 
 void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
 {
+    qDebug() << Q_FUNC_INFO;
     connection()->setTime(event->time);
 
     if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
@@ -2080,9 +2081,10 @@ void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
         const int dpr = int(devicePixelRatio());
         QPoint local(enter->event_x/dpr, enter->event_y/dpr);
         QPoint global(enter->root_x/dpr, enter->root_y/dpr);
-
+        qDebug() << Q_FUNC_INFO << "calling QWindowSystemInterface::handleEnterLeaveEvent() 1)";
         QWindowSystemInterface::handleEnterLeaveEvent(enterWindow->window(), window(), local, global);
     } else {
+        qDebug() << Q_FUNC_INFO << "calling QWindowSystemInterface::handleLeaveEvent() 2)";
         QWindowSystemInterface::handleLeaveEvent(window());
     }
 
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 3486396..a1ca3cc 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2303,6 +2303,7 @@ QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool
  */
 void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, const QPointF &globalPosF)
 {
+    qDebug() << Q_FUNC_INFO <<'>' << enter << leave;
     const QPoint globalPos = globalPosF.toPoint();
 #if 0
     if (leave) {
@@ -2320,9 +2321,9 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con
     QWidget* w ;
     if ((!enter && !leave) || (enter == leave))
         return;
-#ifdef ALIEN_DEBUG
+
     qDebug() << "QApplicationPrivate::dispatchEnterLeave, ENTER:" << enter << "LEAVE:" << leave;
-#endif
+
     QWidgetList leaveList;
     QWidgetList enterList;
 
@@ -2375,6 +2376,9 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con
         }
     }
 
+    qDebug() << "QApplicationPrivate::dispatchEnterLeave2, ENTER:"
+             << enterList << "LEAVE:" << leaveList;
+
     QEvent leaveEvent(QEvent::Leave);
     for (int i = 0; i < leaveList.size(); ++i) {
         w = leaveList.at(i);
@@ -2459,6 +2463,7 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con
         }
     }
 #endif
+    qDebug() << Q_FUNC_INFO <<'<' << enter << leave;
 }
 
 /* exported for the benefit of testing tools */
@@ -2715,15 +2720,20 @@ bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event,
     // Clear the obsolete leaveAfterRelease value, if mouse button has been released but
     // leaveAfterRelease has not been updated.
     // This happens e.g. when modal dialog or popup is shown as a response to button click.
-    if (leaveAfterRelease && !*buttonDown && !event->buttons())
+    if (leaveAfterRelease && !*buttonDown && !event->buttons()) {
+        qDebug() << Q_FUNC_INFO << "clearing leaveAfterRelease";
         leaveAfterRelease = 0;
+    }
 
     if (*buttonDown) {
         if (!graphicsWidget) {
             // Register the widget that shall receive a leave event
             // after the last button is released.
-            if ((alienWidget || !receiver->internalWinId()) && !leaveAfterRelease && !QWidget::mouseGrabber())
+            if ((alienWidget || !receiver->internalWinId()) && !leaveAfterRelease && !QWidget::mouseGrabber()) {
                 leaveAfterRelease = *buttonDown;
+                qDebug() << Q_FUNC_INFO << "assigning leaveAfterRelease="
+                         << leaveAfterRelease;
+            }
             if (event->type() == QEvent::MouseButtonRelease && !event->buttons())
                 *buttonDown = 0;
         }
@@ -2735,9 +2745,12 @@ bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event,
         if ((alienWidget && alienWidget != lastMouseReceiver)
             || (isAlien(lastMouseReceiver) && !alienWidget)) {
             if (activePopupWidget) {
-                if (!QWidget::mouseGrabber())
+                if (!QWidget::mouseGrabber()) {
+                    qDebug() << Q_FUNC_INFO << "calling dispatchEnterLeave 1)";
                     dispatchEnterLeave(alienWidget ? alienWidget : nativeWidget, lastMouseReceiver, event->screenPos());
+                }
             } else {
+                qDebug() << Q_FUNC_INFO << "calling dispatchEnterLeave 2)";
                 dispatchEnterLeave(receiver, lastMouseReceiver, event->screenPos());
             }
 
@@ -2760,16 +2773,22 @@ bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event,
     else
         result = QApplication::sendEvent(receiver, event);
 
+
     if (!graphicsWidget && leaveAfterRelease && event->type() == QEvent::MouseButtonRelease
         && !event->buttons() && QWidget::mouseGrabber() != leaveAfterRelease) {
+        qDebug() << Q_FUNC_INFO << "leaveAfterRelease=" <<leaveAfterRelease
+                 << "mouseGrabber=" << QWidget::mouseGrabber();
         // Dispatch enter/leave if:
         // 1) the mouse grabber is an alien widget
         // 2) the button is released on an alien widget
+
+
         QWidget *enter = 0;
         if (nativeGuard)
             enter = alienGuard ? alienWidget : nativeWidget;
         else // The receiver is typically deleted on mouse release with drag'n'drop.
             enter = QApplication::widgetAt(event->globalPos());
+        qDebug() << Q_FUNC_INFO << "calling dispatchEnterLeave 3)";
         dispatchEnterLeave(enter, leaveAfterRelease, event->screenPos());
         leaveAfterRelease = 0;
         lastMouseReceiver = enter;
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index dccd7ae..451eb13 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -306,6 +306,7 @@ void QWidgetWindow::handleEnterLeaveEvent(QEvent *event)
             QWidget *leave = m_widget;
             if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
                 leave = qt_last_mouse_receiver.data();
+            qDebug() << Q_FUNC_INFO << "calling dispatchEnterLeave() 1)";
             QApplicationPrivate::dispatchEnterLeave(enter, leave, globalPosF);
             qt_last_mouse_receiver = enter;
         }
@@ -313,6 +314,7 @@ void QWidgetWindow::handleEnterLeaveEvent(QEvent *event)
         const QEnterEvent *ee = static_cast<QEnterEvent *>(event);
         QWidget *child = m_widget->childAt(ee->pos());
         QWidget *receiver = child ? child : m_widget;
+        qDebug() << Q_FUNC_INFO << "calling dispatchEnterLeave() 2)";
         QApplicationPrivate::dispatchEnterLeave(receiver, 0, ee->screenPos());
         qt_last_mouse_receiver = receiver;
     }
