diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-09-11 12:25:00 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-09-21 18:36:06 +0200 |
commit | 6c90aa029bb65dc5357ac7a26738e711c97732a2 (patch) | |
tree | 74885782984e4bac15864ae720c23359658c735d /src/widgets/widgets/qdockwidget.cpp | |
parent | f07efb48194925fcf598a2f8ff46cafa8eec1284 (diff) |
QDockWidget: ignore close event if DockWidgetClosable is not set
[ChangeLog][QtWidgets][QDockWidget] A floating dockwidget that doesn't
have the DockWidgetClosable feature flag set can no longer be closed by
a call to QWidget::close or a corresponding keyboard shortcut (such as
Alt+F4).
Fixes: QTBUG-116752
Pick-to: 6.6 6.5
Change-Id: I7859a2eed11f0e4ee013f7f56611e282e9bcae9a
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/widgets/widgets/qdockwidget.cpp')
-rw-r--r-- | src/widgets/widgets/qdockwidget.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index acbe5ffdc9..c04aa36a38 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -1537,7 +1537,13 @@ void QDockWidget::closeEvent(QCloseEvent *event) Q_D(QDockWidget); if (d->state) d->endDrag(true); - QWidget::closeEvent(event); + + // For non-closable widgets, don't allow closing, except when the mainwindow + // is hidden, as otherwise an application wouldn't be able to be shut down. + const QMainWindow *win = qobject_cast<QMainWindow*>(parentWidget()); + const bool canClose = (d->features & DockWidgetClosable) + || (!win || !win->isVisible()); + event->setAccepted(canClose); } /*! \reimp */ |