summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidgetwindow.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-10-13 15:41:28 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-10-20 21:17:08 +0200
commit132ed5eb51c63bd34a5d96fc29e8e3868e5ce5a5 (patch)
tree306f78bd8b9cfc4152104fe475330d384841b66e /src/widgets/kernel/qwidgetwindow.cpp
parenta3c85182682c3dd2b220198f8bd8bc8c593f0f9e (diff)
Centralize maybeLastWindowClosed checking in QWindow
Instead of plumbing QWidgetWindow close events via handleCloseEvent, we just implement closeEvent directly. This allows QWindow do save the state of the window/widget before the close event, so that we know whether we should trigger lastWindowClosed handling, even if the window was deleted as a result of the close event. This also relieves QGuiApplication and QApplication from dealing with the close logic in their notify functions, so that these functions can focus on the propagation of events -- not how the event is handled. Change-Id: I8b586b53a53b1df1d8630c1acb635c60f191bb4b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/kernel/qwidgetwindow.cpp')
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index ba1230301e..c750d9f730 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -120,6 +120,7 @@ public:
}
bool participatesInLastWindowClosed() const override;
+ bool treatAsVisible() const override;
};
QRectF QWidgetWindowPrivate::closestAcceptableGeometry(const QRectF &rect) const
@@ -230,6 +231,7 @@ static inline bool shouldBePropagatedToWidget(QEvent *event)
case QEvent::ChildAdded:
case QEvent::ChildRemoved:
case QEvent::Paint:
+ case QEvent::Close: // Propagated manually in closeEvent
return false;
default:
return true;
@@ -242,15 +244,6 @@ bool QWidgetWindow::event(QEvent *event)
return QWindow::event(event);
switch (event->type()) {
- case QEvent::Close: {
- // The widget might be deleted in the close event handler.
- QPointer<QObject> guard = this;
- handleCloseEvent(static_cast<QCloseEvent *>(event));
- if (guard)
- QWindow::event(event);
- return true;
- }
-
case QEvent::Enter:
case QEvent::Leave:
handleEnterLeaveEvent(event);
@@ -838,7 +831,7 @@ void QWidgetWindow::handleResizeEvent(QResizeEvent *event)
}
}
-void QWidgetWindow::handleCloseEvent(QCloseEvent *event)
+void QWidgetWindow::closeEvent(QCloseEvent *event)
{
Q_D(QWidgetWindow);
bool accepted = m_widget->d_func()->handleClose(d->inClose ? QWidgetPrivate::CloseWithEvent
@@ -860,6 +853,18 @@ bool QWidgetWindowPrivate::participatesInLastWindowClosed() const
return QWindowPrivate::participatesInLastWindowClosed();
}
+bool QWidgetWindowPrivate::treatAsVisible() const
+{
+ Q_Q(const QWidgetWindow);
+
+ // Widget windows may have Qt::WA_DontShowOnScreen, in which case the
+ // QQWidget will be visible, but the corresponding QWindow will not.
+ // Since the lastWindowClosed logic relies on checking whether the
+ // closed window was visible, and if there are any remaining visible
+ // windows, we need to reflect the QWidget state, not the QWindow one.
+ return q->widget()->isVisible();
+}
+
#if QT_CONFIG(wheelevent)
void QWidgetWindow::handleWheelEvent(QWheelEvent *event)