From f6afd8752255ce45be04130b0dd9afa2080f660b Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Sat, 22 Aug 2026 11:08:02 +0200 Subject: [PATCH] Fix dock widget size/position not being restored on Qt6 --- sources/editor/ui/qetelementeditor.cpp | 6 +++++ sources/qetdiagrameditor.cpp | 29 ++++++++++++++++++++---- sources/qetdiagrameditor.h | 1 + sources/titleblock/qettemplateeditor.cpp | 10 +++++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/sources/editor/ui/qetelementeditor.cpp b/sources/editor/ui/qetelementeditor.cpp index 3febab0d9..0a05d64b4 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -952,7 +952,13 @@ void QETElementEditor::readSettings() QVariant state = settings.value("elementeditor/state"); if (state.isValid()) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (!restoreState(state.toByteArray())) { + settings.remove("elementeditor/state"); + } +#else restoreState(state.toByteArray()); +#endif } auto data = m_elmt_scene->elementData(); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index ed2795964..4ad6de7e7 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -132,8 +132,9 @@ QETDiagramEditor::QETDiagramEditor(const QStringList &files, QWidget *parent) : connect(&m_workspace, &QMdiArea::subWindowActivated, this, &QETDiagramEditor::subWindowActivated); connect(QApplication::clipboard(), &QClipboard::dataChanged, this, &QETDiagramEditor::slot_updatePasteAction); - readSettings(); + readSettings(); // restoreGeometry before show() show(); + readSettingsState(); // restoreState() must be called after show() in Qt6 //If valid file path is given as arguments uint opened_projects = 0; @@ -2202,10 +2203,6 @@ void QETDiagramEditor::readSettings() QVariant geometry = settings.value("diagrameditor/geometry"); if (geometry.isValid()) restoreGeometry(geometry.toByteArray()); - // etat de la fenetre (barres d'outils, docks...) - QVariant state = settings.value("diagrameditor/state"); - if (state.isValid()) restoreState(state.toByteArray()); - // gestion des projets (onglets ou fenetres) bool tabbed = settings.value("diagrameditor/viewmode", "tabbed") == "tabbed"; if (tabbed) { @@ -2215,6 +2212,28 @@ void QETDiagramEditor::readSettings() } } +/** + @brief QETDiagramEditor::readSettingsState + Restore the window state (docks, toolbars). + Must be called AFTER show() in Qt6 for restoreState() to work correctly. +*/ +void QETDiagramEditor::readSettingsState() +{ + QSettings settings; + + // etat de la fenetre (barres d'outils, docks...) + QVariant state = settings.value("diagrameditor/state"); + if (state.isValid()) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (!restoreState(state.toByteArray())) { + settings.remove("diagrameditor/state"); + } +#else + restoreState(state.toByteArray()); +#endif + } +} + /** @brief QETDiagramEditor::writeSettings Write the settings diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index a1b08c037..31e6ce82c 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -127,6 +127,7 @@ class QETDiagramEditor : public QETMainWindow void setWindowedMode(); void setTabbedMode(); void readSettings(); + void readSettingsState(); void writeSettings(); void activateProject(QETProject *); void activateProject(ProjectView *); diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index 3a316f15b..6277a25d5 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -648,7 +648,15 @@ void QETTitleBlockTemplateEditor::readSettings() // window state (toolbars, docks...) QVariant state = settings.value("titleblocktemplateeditor/state"); - if (state.isValid()) restoreState(state.toByteArray()); + if (state.isValid()) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (!restoreState(state.toByteArray())) { + settings.remove("titleblocktemplateeditor/state"); + } +#else + restoreState(state.toByteArray()); +#endif + } } /**