I have a layer with a virtual field, "LongLabel", an expression concatenating several of its data fields. When I edit a feature's data fields in the layer's attribute table/form, how can I force the virtual field to update for that feature? I care since "LongLabel" is the feature selector field on the left hand side of the form.
I'm unsurprised "LongLabel" doesn't update immediately, while I remain in that feature in the table. But I was hoping it would update after I switch to a different feature and come back, or when I save my edits and/or reload the table (icons at top), or - at worst - if I toggle editing on and off to force a data provider commit. No change.
The edits to the underlying data fields are correctly captured, it's just the virtual field that doesn't recalc. After the data edit, if I open a 2nd attribute table (F6 from canvas) it correctly displays the updated "LongLabel" in the 2nd table but the unupdated one in the original table.
If there's no way to do it from the QGIS UI, I'd be fine with a PyQGIS solution. An iface.activeLayer().dataProvider().forceReload()
from the Python console doesn't help though. An .activeLayer().commitChanges()
followed by .startEditing()
toggles editing on and off, reflected in the attr table's editing icon, but still not updating the field. I can also find the attribute table widget by searching for
'QgsAttributeTableDialog/'+iface.activeLayer().id()
in [x.objectName() for x in QApplication.instance().allWidgets()]
but can't figure out how to force it to do anything other than .close()
once I've located it.
Editing to add:
I've gone and replaced "LongLabel"
with its expression definition in the layer's display name property. In this case, the LHS feature selector (that used to be "LongLabel") correctly updates when I move away from the edited feature. However, "LongLabel" as a field in the attribute form still does not update. So it's related specifically to virtual fields. Using QGis 3.10.0.