From be86a772ce4e631fb6ba36f550befd1b5396a126 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 7 Nov 2022 08:19:00 +0100 Subject: [PATCH] Implemented custom close handling for dynamically created image viewers --- demo/MainWindow.cpp | 19 ++++++++++++++++--- demo/MainWindow.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 1325404..1509b4b 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -873,6 +873,20 @@ void CMainWindow::onEditorCloseRequested() } +//============================================================================ +void CMainWindow::onImageViewerCloseRequested() +{ + auto DockWidget = qobject_cast(sender()); + int Result = QMessageBox::question(this, "Close Image Viewer", QString("%1 " + "contains unsaved changes? Would you like to close it?") + .arg(DockWidget->windowTitle())); + if (QMessageBox::Yes == Result) + { + DockWidget->closeDockWidget(); + } +} + + //============================================================================ void CMainWindow::createTable() { @@ -931,9 +945,8 @@ void CMainWindow::createImageViewer() DockWidget->setFeature(ads::CDockWidget::DockWidgetForceCloseWithArea, true); DockWidget->setFeature(ads::CDockWidget::CustomCloseHandling, true); DockWidget->resize(QSize(640, 480)); - connect(DockWidget, &ads::CDockWidget::closeRequested, [this](){ - qDebug() << "ImageViewer close requested"; - }); + connect(DockWidget, &ads::CDockWidget::closeRequested, this, + &CMainWindow::onImageViewerCloseRequested); if (a->text().startsWith("Floating")) { diff --git a/demo/MainWindow.h b/demo/MainWindow.h index 0eeb525..4afee14 100644 --- a/demo/MainWindow.h +++ b/demo/MainWindow.h @@ -63,6 +63,7 @@ private slots: void createEditor(); void createTable(); void onEditorCloseRequested(); + void onImageViewerCloseRequested(); void showStatusDialog(); void toggleDockWidgetWindowTitle(); void applyVsStyle();