diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index bb7000a..035a203 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3302,6 +3302,8 @@ QDebug operator<<(QDebug dbg, const QEvent *e) {
                       << ", " << hex << (int)me->modifiers() << dec;
         if (const Qt::MouseEventSource source = me->source())
             nsp << ", source = " << source;
+        if (const Qt::MouseEventFlags flags = me->flags())
+            nsp << ", flags = " << int(flags);
         nsp << ')';
     }
     return dbg.space();
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 8ccff43..1c1e7d4 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1618,6 +1618,7 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
 
 void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
 {
+    qDebug() << "QGuiApplicationPrivate::processMouseEvent() enter" << e->window <<e->buttons;
     QEvent::Type type;
     Qt::MouseButtons stateChange = e->buttons ^ buttons;
     if (e->globalPos != QGuiApplicationPrivate::lastCursorPosition && (stateChange != Qt::NoButton)) {
@@ -1673,6 +1674,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
         if (button & e->buttons) {
             ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval());
             doubleClick = e->timestamp - mousePressTime < doubleClickInterval && button == mousePressButton;
+            qDebug() << "QGuiApplicationPrivate::processMouseEvent() doubleClick=" <<doubleClick <<e->window ;
             type = frameStrut ? QEvent::NonClientAreaMouseButtonPress : QEvent::MouseButtonPress;
             mousePressTime = e->timestamp;
             mousePressButton = button;
@@ -1700,6 +1702,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
 
     if (window->d_func()->blockedByModalWindow) {
         // a modal window is blocking this window, don't allow mouse events through
+        qDebug() << "QGuiApplicationPrivate::processMouseEvent() return blockedByModalWindow)";
         return;
     }
 
@@ -1707,6 +1710,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
         // QtBUG-25831, used to suppress delivery in qwidgetwindow.cpp
         setMouseEventFlags(&ev, ev.flags() | Qt::MouseEventCreatedDoubleClick);
     }
+    qDebug() << "QGuiApplicationPrivate::processMouseEvent() sending=" <<window<<&ev;
 
     QGuiApplication::sendSpontaneousEvent(window, &ev);
     if (!e->synthetic && !ev.isAccepted()
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 0b983e7..6d0566d 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2467,6 +2467,7 @@ QWidget *QApplicationPrivate::pickMouseReceiver(QWidget *candidate, const QPoint
     QWidget *mouseGrabber = QWidget::mouseGrabber();
     if (((type == QEvent::MouseMove && buttons) || (type == QEvent::MouseButtonRelease))
             && !buttonDown && !mouseGrabber) {
+        qDebug() << "QApplicationPrivate::pickMouseReceiver returns NULL buttonDown" << buttonDown;
         return 0;
     }
 
@@ -2633,8 +2634,10 @@ void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget)
     if (widgetInShow && widgetUnderCursor != widget && !widget->isAncestorOf(widgetUnderCursor))
         return; // Mouse cursor not inside the widget or any of its children.
 
-    if (widget->data->in_destructor && qt_button_down == widget)
+    if (widget->data->in_destructor && qt_button_down == widget) {
+        qDebug() << __FUNCTION__ << "clearing qt_button_down";
         qt_button_down = 0;
+    }
 
     // Send enter/leave events followed by a mouse move on the entered widget.
     QMouseEvent e(QEvent::MouseMove, pos, windowPos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
@@ -4055,6 +4058,7 @@ void QApplicationPrivate::notifyDragStarted(const QDrag *drag)
 {
     // Prevent pickMouseReceiver() from using the widget where the drag was started after a drag operation.
     QGuiApplicationPrivate::notifyDragStarted(drag);
+    qDebug() << __FUNCTION__ << "clearing qt_button_down";
     qt_button_down = 0;
 }
 #endif // QT_NO_DRAGANDDROP
diff --git a/src/widgets/kernel/qapplication_qpa.cpp b/src/widgets/kernel/qapplication_qpa.cpp
index 5893c52..3a99261 100644
--- a/src/widgets/kernel/qapplication_qpa.cpp
+++ b/src/widgets/kernel/qapplication_qpa.cpp
@@ -187,6 +187,7 @@ void QApplicationPrivate::closePopup(QWidget *popup)
     popupWidgets->removeAll(popup);
 
      if (popup == qt_popup_down) {
+         qDebug() << "QApplicationPrivate::closePopup clearing qt_button_down";
          qt_button_down = 0;
          qt_popup_down = 0;
      }
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index 35a526e..c543ca9 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -259,6 +259,7 @@ bool QWidgetWindow::event(QEvent *event)
     case QEvent::Hide:
         return QWindow::event(event);
     case QEvent::WindowBlocked:
+        qDebug() << __FUNCTION__ << "clearing qt_button_down";
         qt_button_down = 0;
         break;
     default:
@@ -361,6 +362,8 @@ void QWidgetWindow::handleNonClientAreaMouseEvent(QMouseEvent *e)
 
 void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
 {
+    if (event->type() != QEvent::MouseMove)
+            qDebug() << "QWidgetWindow::handleMouseEvent() " << m_widget <<event;
     static const QEvent::Type contextMenuTrigger =
         QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
         QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
@@ -374,6 +377,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
         QWidget *popupChild  = popup->childAt(mapped);
 
         if (popup != qt_popup_down) {
+            qDebug() << "QWidgetWindow::handleMouseEvent clearing qt_button_down, popup != qt_popup_down, popup=" << popup;
             qt_button_down = 0;
             qt_popup_down = 0;
         }
@@ -381,6 +385,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
         switch (event->type()) {
         case QEvent::MouseButtonPress:
         case QEvent::MouseButtonDblClick:
+            qDebug() << "QWidgetWindow::handleMouseEvent assigning qt_button_down" <<  popupChild;
             qt_button_down = popupChild;
             qt_popup_down = popup;
             break;
@@ -424,8 +429,10 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
 
         if (qApp->activePopupWidget() != activePopupWidget
             && qt_replay_popup_mouse_event) {
-            if (m_widget->windowType() != Qt::Popup)
+            if (m_widget->windowType() != Qt::Popup) {
+                qDebug() << "QWidgetWindow::handleMouseEvent() qt_button_down=0, " << m_widget << "no popup";
                 qt_button_down = 0;
+            }
             if (event->type() == QEvent::MouseButtonPress) {
                 // the popup disappeared, replay the mouse press event
                 QWidget *w = QApplication::widgetAt(event->globalPos());
@@ -466,6 +473,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
         }
 
         if (releaseAfter) {
+            qDebug() << "QWidgetWindow::handleMouseEvent() qt_button_down=0, releaseAfter" << m_widget;
             qt_button_down = 0;
             qt_popup_down = 0;
         }
@@ -483,8 +491,12 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
     if (!widget)
         widget = m_widget;
 
-    if (event->type() == QEvent::MouseButtonPress)
+    if (event->type() == QEvent::MouseButtonPress) {
         qt_button_down = widget;
+        qDebug() << "QWidgetWindow::handleMouseEvent() qt_button_down=" << qt_button_down << "m_widget=" << m_widget;
+    } else {
+        qDebug() << "QWidgetWindow::handleMouseEvent() not touching qt_button_down (" << qt_button_down << ')' << "m_widget=" << m_widget;
+    }
 
     QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(),
                                                                qt_button_down, widget);
@@ -492,8 +504,12 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
     if (!receiver) {
         if (event->type() == QEvent::MouseButtonRelease)
             QApplicationPrivate::mouse_buttons &= ~event->button();
+        qDebug() << "QWidgetWindow::handleMouseEvent() discarding release " << m_widget;
         return;
     }
+    if (event->type() == QEvent::MouseButtonRelease)
+        qDebug() << "QWidgetWindow::handleMouseEvent() handling release " << m_widget;
+
     if ((event->type() != QEvent::MouseButtonPress)
         || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) {
 
