From ed86a4f25322ab0d08ad8ee9d3c507146573b1e0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 20 Apr 2020 14:06:53 +0200 Subject: Don't send QEvent::Hide to an already hidden top level widget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When hiding a popup by clicking outside of its area, a window is closed. Depending on the platform specific implementation details, this can result in multiple calls to QWidgetPrivate::setVisible(false). The first one from the handling of the close event in QWidgetWindow::event; the second from the destruction of the window in QWindow::event. Since the first call already sets the Qt::WA_WState_Hidden flag before calling QWidgetPrivate::hide_helper, we can test if the flag is set and skip the second call if it is. The included test does not reproduce the issue, as that issue only reproduces if the close event is generated by the mouse event handling in the Cocoa platform plugin (which doesn't call QWidget::close, but rather sends a native close event to the platform window). However, it verifies that the fix doesn't introduce any regressions. Change-Id: Id0eda9326a8adf0cc1f6a3840f9ac0b635ab39a1 Fixes: QTBUG-79134 Pick-to: 5.15 Reviewed-by: Qt CI Bot Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e4e09c17be..6e3e9e0414 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -8102,9 +8102,11 @@ void QWidgetPrivate::setVisible(bool visible) if (!q->isWindow() && q->parentWidget()) // && !d->getOpaqueRegion().isEmpty()) q->parentWidget()->d_func()->setDirtyOpaqueRegion(); - q->setAttribute(Qt::WA_WState_Hidden); - if (q->testAttribute(Qt::WA_WState_Created)) - hide_helper(); + if (!q->testAttribute(Qt::WA_WState_Hidden)) { + q->setAttribute(Qt::WA_WState_Hidden); + if (q->testAttribute(Qt::WA_WState_Created)) + hide_helper(); + } // invalidate layout similar to updateGeometry() if (!q->isWindow() && q->parentWidget()) { -- cgit v1.2.3