diff --git a/sources/ui/compositetexteditdialog.cpp b/sources/ui/compositetexteditdialog.cpp index 8c9571d0f..bc3fc5962 100644 --- a/sources/ui/compositetexteditdialog.cpp +++ b/sources/ui/compositetexteditdialog.cpp @@ -84,3 +84,14 @@ void CompositeTextEditDialog::on_m_info_cb_activated(const QString &arg1) Q_UNUSED(arg1) ui->m_plain_text_edit->insertPlainText(ui->m_info_cb->currentData().toString()); } + +/** + * @brief CompositeTextEditDialog::focusInEvent + * Reimplemented from QWidget::focusInEvent + * @param event + */ +void CompositeTextEditDialog::focusInEvent(QFocusEvent *event) +{ + ui->m_plain_text_edit->setFocus(); + QDialog::focusInEvent(event); +} diff --git a/sources/ui/compositetexteditdialog.h b/sources/ui/compositetexteditdialog.h index 502397a77..7329cb759 100644 --- a/sources/ui/compositetexteditdialog.h +++ b/sources/ui/compositetexteditdialog.h @@ -28,6 +28,9 @@ class CompositeTextEditDialog : public QDialog private slots: void on_m_info_cb_activated(const QString &arg1); + + protected: + void focusInEvent(QFocusEvent *event) override; private : void setUpComboBox(); diff --git a/sources/ui/dynamicelementtextmodel.cpp b/sources/ui/dynamicelementtextmodel.cpp index 18570aae1..c58307670 100644 --- a/sources/ui/dynamicelementtextmodel.cpp +++ b/sources/ui/dynamicelementtextmodel.cpp @@ -563,6 +563,7 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti case DynamicElementTextModel::textFrom: { QComboBox *qcb = new QComboBox(parent); + qcb->setObjectName("text_from"); qcb->addItem(tr("Texte utilisateur")); qcb->addItem(tr("Information de l'élément")); qcb->addItem(tr("Texte composé")); @@ -716,6 +717,13 @@ bool DynamicTextItemDelegate::eventFilter(QObject *object, QEvent *event) emit commitData(sb); } + //Like the hack above, change the current index of the combobox, apply the change immediately, no need to lose focus or press enter. + if((object->objectName() == "text_from" || object->objectName() == "info_text") && event->type() == QEvent::FocusIn) + { + QComboBox *qcb = static_cast(object); + connect(qcb, static_cast(&QComboBox::currentIndexChanged), [this,qcb](){emit commitData(qcb);}); + } + return QStyledItemDelegate::eventFilter(object, event); } diff --git a/sources/ui/dynamicelementtextmodel.h b/sources/ui/dynamicelementtextmodel.h index 7ea905d3c..0c7c312c9 100644 --- a/sources/ui/dynamicelementtextmodel.h +++ b/sources/ui/dynamicelementtextmodel.h @@ -73,6 +73,8 @@ class DynamicElementTextModel : public QStandardItemModel class DynamicTextItemDelegate : public QStyledItemDelegate { + Q_OBJECT + public: DynamicTextItemDelegate(QObject *parent = Q_NULLPTR);