diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp index a974ac4fdf..6a654898bf 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp @@ -153,7 +153,7 @@ static void printFocusChain(QWidget *widget) { QWidget* start = widget; int i = 0; do { - FC_ERR(" " << widget->objectName().toStdString(); + FC_ERR(" " << widget->objectName().toStdString()); widget = widget->nextInFocusChain(); i++; } while (widget != nullptr && i < 30 && start != widget); @@ -245,12 +245,24 @@ static PropertyEditor::PropertyItem *createPropertyItem(App::Property *prop) return item; } +void DlgAddPropertyVarSet::removeSelectionEditor() +{ + // If the editor has a lineedit, then Qt selects the string inside it when + // the editor is created. This interferes with the editor getting focus. + // For example, units will then be selected as well, whereas this is not + // the behavior we want. We therefore deselect the text in the lineedit. + if (auto lineEdit = editor->findChild()) { + lineEdit->deselect(); + } +} + void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem, [[maybe_unused]]std::string& type) { editor.reset(propertyItem->createEditor(this, [this]() { this->valueChanged(); })); + editor->blockSignals(true); propertyItem->setEditorData( editor.get(), propertyItem->data(PropertyEditor::PropertyItem::ValueColumn, Qt::EditRole)); @@ -262,6 +274,9 @@ void DlgAddPropertyVarSet::addEditor(PropertyEditor::PropertyItem* propertyItem, QWidget::setTabOrder(ui->comboBoxType, editor.get()); QWidget::setTabOrder(editor.get(), ui->checkBoxAdd); + removeSelectionEditor(); + editor->blockSignals(false); + // FC_ERR("add editor"); // printFocusChain(editor.get()); } diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.h b/src/Gui/Dialogs/DlgAddPropertyVarSet.h index d59a684cf6..3c797db686 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.h +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.h @@ -92,6 +92,7 @@ private: void clearCurrentProperty(); void removeEditor(); + void removeSelectionEditor(); void addEditor(PropertyEditor::PropertyItem* propertyItem, std::string& type); bool isTypeWithEditor(const std::string& type);