[Core] Fix value field unit selection
Qt automatically selects the text in the value field on creation. This interferes with the selection when the field has focus. This commit ensures that the automatic selection is undone.
This commit is contained in:
@@ -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<QLineEdit*>()) {
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user