From 32b727864032ae84f4b203fa523fe2804d1eaa02 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Date: Wed, 14 Sep 2022 16:02:36 +0200 Subject: [PATCH] Clear WA_UnderMouse attribute when widget gets hidden From 6.3 onward, hiding a widget doesn't automatically clear QT::WA_UnderMouse attribute. This leads to multiple buttons drawn with highlighted rectangle at the same time (refer bug). The behavior is observed after commit 0246bfd40a2cc5ea9cfc035146e6dd865b334c68 made as part of bug QTBUG-53286. This patch clears WA_UnderMouse attribute in widget hideChildren() and subsequently, widgets that are hidden will not inherit this attribute on the next show operation. The attribute will be set only when the widget is under mouse cursor. Fixes: QTBUG-104805 Change-Id: I4988eb72577fd557a328fd08bb09fa2fbded3138 Reviewed-by: Volker Hilsheimer (cherry picked from commit 82e7ac23a035a1c034d2ed665ecaeeb72914b715) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/kernel/qwidget.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 2cd30794cda..93e838d8b82 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -8339,6 +8339,7 @@ void QWidgetPrivate::showChildren(bool spontaneous) void QWidgetPrivate::hideChildren(bool spontaneous) { + Q_Q(QWidget); QList childList = children; for (int i = 0; i < childList.size(); ++i) { QWidget *widget = qobject_cast(childList.at(i)); @@ -8370,6 +8371,14 @@ void QWidgetPrivate::hideChildren(bool spontaneous) } #endif } + + // If the window of this widget is not closed, then the leave event + // will eventually handle the widget under mouse use case. + // Otherwise, we need to explicitly handle it here. + if (QWidget* widgetWindow = q->window(); + widgetWindow && widgetWindow->data->is_closing) { + q->setAttribute(Qt::WA_UnderMouse, false); + } } /*!