Persist QColorDialog custom colors across application restarts

Qt's QColorDialog loads custom colors from QSettings on startup but
never writes them back, so user-defined colors in the color picker
are lost when the application exits.

Save and load the 16 custom color slots explicitly via QSettings
in QETApp's constructor (after initStyle) and destructor (before
other settings are flushed). This covers every QColorDialog usage
in the application transparently.

Also fixes a QColorDialog memory leak in DiagramView.
This commit is contained in:
Kellermorph
2026-09-18 11:13:26 +02:00
parent 918756a91a
commit fa52aab149
4 changed files with 65 additions and 1 deletions
+4 -1
View File
@@ -40,6 +40,7 @@
#include "NameList/nameslist.h"
#include "elementdialog.h"
#include <QDropEvent>
#include <QPointer>
/**
Constructeur
@@ -122,7 +123,7 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
ConductorProperties initial_properties = edited_conductor->properties();
// prepare a color dialog showing the initial conductor color
QColorDialog *color_dialog = new QColorDialog(this);
QPointer<QColorDialog> color_dialog = new QColorDialog(this);
color_dialog->setWindowTitle(tr("Choisir la nouvelle couleur de ce conducteur"));
#ifdef Q_OS_MACOS
color_dialog -> setWindowFlags(Qt::Sheet);
@@ -150,6 +151,8 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
LastUsedStyle::setConductorColor(new_color);
}
}
if (color_dialog)
delete color_dialog;
});
}