From a0f0640c9f487bf9643ea5ee486d1a1ce9c15a1b Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Fri, 29 Jul 2022 13:25:14 +0200 Subject: [PATCH] Fixed CustomCloseHandling for floating widgets --- demo/MainWindow.cpp | 16 +++++++++++++++- src/FloatingDockContainer.cpp | 12 +++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index b7a2b2b..6d8d0c9 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -458,7 +458,21 @@ void MainWindowPrivate::createContent() DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(), RighDockArea); auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(), RighDockArea); DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(), RighDockArea); - DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(), BottomDockArea); + auto LabelDockWidget = createLongTextLabelDockWidget(); + std::cout << "DockWidget " << LabelDockWidget->objectName().toStdString() << std::endl; + DockManager->addDockWidget(ads::CenterDockWidgetArea, LabelDockWidget, BottomDockArea); + + // Tests CustomCloseHandling without DeleteOnClose + LabelDockWidget->setFeature(ads::CDockWidget::CustomCloseHandling, true); + QObject::connect(LabelDockWidget, &ads::CDockWidget::closeRequested, [LabelDockWidget, this]() + { + int Result = QMessageBox::question(_this, "Custom Close Request", + "Do you really want to close this dock widget?"); + if (QMessageBox::Yes == Result) + { + LabelDockWidget->closeDockWidget(); + } + }); Action = ui.menuTests->addAction(QString("Set %1 Floating").arg(DockWidget->windowTitle())); DockWidget->connect(Action, SIGNAL(triggered()), SLOT(setFloating())); diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index a349e13..2a32786 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -807,11 +807,16 @@ void CFloatingDockContainer::closeEvent(QCloseEvent *event) return; } + bool HasOpenDockWidgets = false; for (auto DockWidget : d->DockContainer->openedDockWidgets()) { if (DockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose) || DockWidget->features().testFlag(CDockWidget::CustomCloseHandling)) { - DockWidget->closeDockWidgetInternal(); + bool Closed = DockWidget->closeDockWidgetInternal(); + if (!Closed) + { + HasOpenDockWidgets = true; + } } else { @@ -819,6 +824,11 @@ void CFloatingDockContainer::closeEvent(QCloseEvent *event) } } + if (HasOpenDockWidgets) + { + return; + } + // In Qt version after 5.9.2 there seems to be a bug that causes the // QWidget::event() function to not receive any NonClientArea mouse // events anymore after a close/show cycle. The bug is reported here: