Fix dock widget size/position not being restored on Qt6

This commit is contained in:
Kellermorph
2026-08-22 11:08:02 +02:00
parent f951c20586
commit f6afd87522
4 changed files with 40 additions and 6 deletions
+24 -5
View File
@@ -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