fix: update lineedit if setting changed externally (#6286)

This commit is contained in:
pajlada
2025-06-21 13:02:59 +02:00
committed by GitHub
parent da96528b55
commit f7af1138b3
2 changed files with 14 additions and 3 deletions
+13 -3
View File
@@ -202,7 +202,6 @@ SettingWidget *SettingWidget::lineEdit(const QString &label,
QStringSetting &setting,
const QString &placeholderText)
{
QColor color(setting.getValue());
auto *widget = new SettingWidget(label);
auto *lbl = new QLabel(label + ":");
@@ -215,15 +214,26 @@ SettingWidget *SettingWidget::lineEdit(const QString &label,
}
widget->hLayout->addWidget(lbl);
// widget->hLayout->addStretch(1);
widget->hLayout->addWidget(edit);
// update when setting changes
// Update the setting when the widget changes.
QObject::connect(edit, &QLineEdit::textChanged,
[&setting](const QString &newValue) {
setting = newValue;
});
// Update the widget to reflect the new setting value if the setting changes
// This _will_ fire every time the widget changes, so we are being conservative
// with the `setText` call to ensure the user doesn't get their cursor bounced around.
setting.connect(
[edit](const QString &value) {
if (edit->text() != value)
{
edit->setText(value);
}
},
widget->managedConnections, false);
widget->actionWidget = edit;
widget->label = lbl;