diff --git a/sources/ui/dynamicelementtextmodel.cpp b/sources/ui/dynamicelementtextmodel.cpp index e210ffba5..6ad12570a 100644 --- a/sources/ui/dynamicelementtextmodel.cpp +++ b/sources/ui/dynamicelementtextmodel.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include static int src_txt_row = 0; @@ -1595,6 +1596,15 @@ DynamicTextItemDelegate::DynamicTextItemDelegate(QObject *parent) : QStyledItemDelegate(parent) {} +void DynamicTextItemDelegate::commitAndCloseDeferred(QWidget *editor) const +{ + auto *self = const_cast(this); + QTimer::singleShot(0, self, [self, editor]() { + emit self->commitData(editor); + emit self->closeEditor(editor); + }); +} + QWidget *DynamicTextItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, @@ -1682,6 +1692,7 @@ QWidget *DynamicTextItemDelegate::createEditor( w->setProperty("ok", ok); } w->setObjectName("font_dialog"); + commitAndCloseDeferred(w); return w; } case DynamicElementTextModel::color: @@ -1716,6 +1727,7 @@ QWidget *DynamicTextItemDelegate::createEditor( w->setProperty("ok", true); } w->setObjectName("color_dialog"); + commitAndCloseDeferred(w); return w; } case DynamicElementTextModel::pos: diff --git a/sources/ui/dynamicelementtextmodel.h b/sources/ui/dynamicelementtextmodel.h index 67b42e23e..013d9318b 100644 --- a/sources/ui/dynamicelementtextmodel.h +++ b/sources/ui/dynamicelementtextmodel.h @@ -155,6 +155,21 @@ class DynamicTextItemDelegate : public QStyledItemDelegate private: QStringList availableInfo(DynamicElementTextItem *deti) const; + /** + @brief commitAndCloseDeferred + Schedule commitData()/closeEditor() for @a editor on the next + event loop iteration. For editors resolved synchronously inside + createEditor() (font/color, both run their picker dialog before + returning) there is no user interaction left to drive the base + QStyledItemDelegate::eventFilter()'s usual Enter/focus-out commit + path, so without this the value sits picked-but-uncommitted + until something unrelated (e.g. clicking elsewhere) happens to + trigger it. Deferred rather than called immediately: the view + only registers the widget createEditor() returns as "the active + editor" *after* createEditor() itself returns, so emitting here + would target an editor the view doesn't know about yet. + */ + void commitAndCloseDeferred(QWidget *editor) const; }; #endif // DYNAMICELEMENTTEXTMODEL_H