From ad2e8663325c0dc994ebff76f9db1baa34c4c76b Mon Sep 17 00:00:00 2001 From: tetektoza Date: Fri, 3 Oct 2025 13:54:40 +0200 Subject: [PATCH] Gui: Fix window restoration after Edit->Alignment completion After completing Edit->Alignment, main window remains small instead of maximized. It looks like this is Qt 6 regression as the automatic maximization behavior was somehow changed. Previously it didn't need explicit handling to restore the maximisation. So, this patch preserves the previous window state before entering Alignment editor and restores window being maximized/minimized or normal upon finishing the operation. --- src/Gui/ManualAlignment.cpp | 41 +++++++++++++++++++++++++++++++++++++ src/Gui/ManualAlignment.h | 4 ++++ 2 files changed, 45 insertions(+) diff --git a/src/Gui/ManualAlignment.cpp b/src/Gui/ManualAlignment.cpp index a37af55c7e..4948e987c0 100644 --- a/src/Gui/ManualAlignment.cpp +++ b/src/Gui/ManualAlignment.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include # include # include @@ -791,6 +792,18 @@ void ManualAlignment::startAlignment(Base::Type mousemodel) if (myAlignModel.isEmpty()) return; +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + // save the current window state before opening the alignment viewer + previousWindowState = Qt::WindowNoState; + if (auto* activeDoc = Gui::Application::Instance->activeDocument()) { + if (auto* activeView = activeDoc->getActiveView()) { + if (auto* subWindow = qobject_cast(activeView->parentWidget())) { + previousWindowState = subWindow->windowState(); + } + } + } +#endif + // create a split window for picking the points myViewer = new AlignmentView(myDocument,Gui::getMainWindow()); myViewer->setWindowTitle(tr("Alignment[*]")); @@ -874,6 +887,34 @@ void ManualAlignment::closeViewer() if (myViewer->parentWidget()) myViewer->parentWidget()->deleteLater(); myViewer = nullptr; + +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + QTimer::singleShot(0, [this]() { + auto* activeDoc = Gui::Application::Instance->activeDocument(); + if (!activeDoc) { + return; + } + + auto* activeView = activeDoc->getActiveView(); + if (!activeView) { + return; + } + + Gui::getMainWindow()->setActiveWindow(activeView); + if (auto* subWindow = qobject_cast(activeView->parentWidget())) { + // restore the previous window state + if (previousWindowState & Qt::WindowMaximized) { + subWindow->showMaximized(); + } + else if (previousWindowState & Qt::WindowMinimized) { + subWindow->showMinimized(); + } + else { + subWindow->showNormal(); + } + } + }); +#endif } /** diff --git a/src/Gui/ManualAlignment.h b/src/Gui/ManualAlignment.h index 95b1f0a5bc..d3dbb4dc61 100644 --- a/src/Gui/ManualAlignment.h +++ b/src/Gui/ManualAlignment.h @@ -262,6 +262,10 @@ private: int myPickPoints; Base::Placement myTransform; +#if QT_VERSION >= QT_VERSION_CHECK(6,0,0) + Qt::WindowStates previousWindowState; +#endif + class Private; Private* d; };