From f6afd8752255ce45be04130b0dd9afa2080f660b Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Sat, 22 Aug 2026 11:08:02 +0200 Subject: [PATCH 1/3] 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 + } } /** From 61a160fa624f4329cc1c5919b0fec12c6a58411f Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Sun, 23 Aug 2026 10:37:52 +0200 Subject: [PATCH 2/3] Fix restoreState() for QETElementEditor and QETTitleBlockTemplateEditor on Qt6 Apply the same split readSettings()/readSettingsState() pattern from QETDiagramEditor to the other two main windows: - QETElementEditor: split in constructor, call readSettingsState() after show() - QETTitleBlockTemplateEditor: split readSettings(), callers call readSettingsState() after show() (newTemplate + 2x openTitleBlockTemplate) - Remove destructive settings.remove() guards that would delete saved state on every Qt6 launch when restoreState() fails before show() Co-authored-by: ispyisail --- sources/editor/ui/qetelementeditor.cpp | 25 ++++++++++++++++-------- sources/editor/ui/qetelementeditor.h | 1 + sources/qetapp.cpp | 2 ++ sources/titleblock/qettemplateeditor.cpp | 18 +++++++++++++---- sources/titleblock/qettemplateeditor.h | 1 + 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/sources/editor/ui/qetelementeditor.cpp b/sources/editor/ui/qetelementeditor.cpp index 0a05d64b4..a46c56aa5 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -77,8 +77,9 @@ QETElementEditor::QETElementEditor(QWidget *parent) : //ui->m_display_menu->insertMenu(ui->m_zoom_in_action, menu); setWindowState(Qt::WindowMaximized); - readSettings(); + readSettings(); // restoreGeometry before show() show(); + readSettingsState(); // restoreState() must be called after show() in Qt6 } /** @@ -950,20 +951,28 @@ void QETElementEditor::readSettings() restoreGeometry(geometry.toByteArray()); } + auto data = m_elmt_scene->elementData(); + data.m_drawing_information = settings.value("elementeditor/default-informations", "").toString(); + m_elmt_scene->setElementData(data); +} + +/** + * @brief QETElementEditor::readSettingsState + * Restore the window state (docks, toolbars). + * Must be called AFTER show() in Qt6 for restoreState() to work correctly. + */ +void QETElementEditor::readSettingsState() +{ + QSettings settings; + 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"); - } + restoreState(state.toByteArray()); #else restoreState(state.toByteArray()); #endif } - - auto data = m_elmt_scene->elementData(); - data.m_drawing_information = settings.value("elementeditor/default-informations", "").toString(); - m_elmt_scene->setElementData(data); } /** diff --git a/sources/editor/ui/qetelementeditor.h b/sources/editor/ui/qetelementeditor.h index 579d9bab4..b164017f8 100644 --- a/sources/editor/ui/qetelementeditor.h +++ b/sources/editor/ui/qetelementeditor.h @@ -116,6 +116,7 @@ class QETElementEditor : public QMainWindow private: bool canClose(); void readSettings(); + void readSettingsState(); void writeSettings() const; void setupActions(); void updateAction(); diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index d8afcc34b..0463be2ee 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -1975,6 +1975,7 @@ void QETApp::openTitleBlockTemplate(const TitleBlockTemplateLocation &location, qet_template_editor -> setOpenForDuplication(duplicate); qet_template_editor -> edit(location); qet_template_editor -> show(); + qet_template_editor -> readSettingsState(); // must run after show() in Qt6 } /** @@ -1986,6 +1987,7 @@ void QETApp::openTitleBlockTemplate(const QString &filepath) { QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor(); qet_template_editor -> edit(filepath); qet_template_editor -> show(); + qet_template_editor -> readSettingsState(); // must run after show() in Qt6 } /** diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index 6277a25d5..4195c30ba 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -358,6 +358,7 @@ void QETTitleBlockTemplateEditor::newTemplate() QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor(); qet_template_editor -> edit(TitleBlockTemplateLocation()); qet_template_editor -> show(); + qet_template_editor -> readSettingsState(); // must run after show() in Qt6 } /** @@ -645,14 +646,23 @@ void QETTitleBlockTemplateEditor::readSettings() // window size and position QVariant geometry = settings.value("titleblocktemplateeditor/geometry"); if (geometry.isValid()) restoreGeometry(geometry.toByteArray()); +} + +/** + @brief QETTitleBlockTemplateEditor::readSettingsState + Restore the window state (docks, toolbars). + Must be called AFTER show() in Qt6 for restoreState() to work correctly + -- callers are responsible for calling this after show(), since this + window isn't shown by its own constructor. +*/ +void QETTitleBlockTemplateEditor::readSettingsState() +{ + QSettings settings; - // window state (toolbars, docks...) QVariant state = settings.value("titleblocktemplateeditor/state"); if (state.isValid()) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - if (!restoreState(state.toByteArray())) { - settings.remove("titleblocktemplateeditor/state"); - } + restoreState(state.toByteArray()); #else restoreState(state.toByteArray()); #endif diff --git a/sources/titleblock/qettemplateeditor.h b/sources/titleblock/qettemplateeditor.h index 67ac3c231..cfb6709b7 100644 --- a/sources/titleblock/qettemplateeditor.h +++ b/sources/titleblock/qettemplateeditor.h @@ -108,6 +108,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow { public slots: void readSettings(); + void readSettingsState(); void writeSettings(); void selectedCellsChanged(const QList&); void duplicateCurrentLocation(); From 8f6f41ed19ec116401bc9d36ad4f68de3a31ffc9 Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Sun, 23 Aug 2026 18:25:23 +0200 Subject: [PATCH 3/3] Clean up readSettingsState() in all three editors - Remove dead #if QT_VERSION conditionals (both branches were identical) - Add settings.remove() guard on restoreState() failure consistently across all three editors (now safe since all run after show()) --- sources/editor/ui/qetelementeditor.cpp | 8 +++----- sources/qetdiagrameditor.cpp | 4 ---- sources/titleblock/qettemplateeditor.cpp | 8 +++----- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/sources/editor/ui/qetelementeditor.cpp b/sources/editor/ui/qetelementeditor.cpp index a46c56aa5..38fb6a8b7 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -967,11 +967,9 @@ void QETElementEditor::readSettingsState() QVariant state = settings.value("elementeditor/state"); if (state.isValid()) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - restoreState(state.toByteArray()); -#else - restoreState(state.toByteArray()); -#endif + if (!restoreState(state.toByteArray())) { + settings.remove("elementeditor/state"); + } } } diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 4ad6de7e7..d33426aa4 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -2224,13 +2224,9 @@ void QETDiagramEditor::readSettingsState() // 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 } } diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index 4195c30ba..e3a44ecbb 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -661,11 +661,9 @@ void QETTitleBlockTemplateEditor::readSettingsState() QVariant state = settings.value("titleblocktemplateeditor/state"); if (state.isValid()) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - restoreState(state.toByteArray()); -#else - restoreState(state.toByteArray()); -#endif + if (!restoreState(state.toByteArray())) { + settings.remove("titleblocktemplateeditor/state"); + } } }