[QGIS-Developer] Changing attributes of a newly created feature in Python form init code
Stefanos Natsis
uclaros at gmail.com
Wed Jan 10 12:06:04 PST 2024
Hi Hannes
This looks like an XY problem case!
If your actual goal is to:
> Any pointers on how to properly update a new feature's attribute fields,
> that exist on a layer but are not shown the user with the QGIS' widgets
> in the attribute form?
then you simply need to set a Default Value for the field widget but not
add it to the drag and drop form designer. :)
If you really want to do this using form init code, you cannot do it using
the form's feature object as it is actually copied by QgsAttributeForm
before being saved to the layer.
You could connect to QgsAttributeForm::featureSaved() signal instead, that
emits the actual feature, but apparently the my_form_open function is
called twice: once when the form is loaded and once after OK is clicked
(bug??), so that would create the connection twice!
To avoid this you could connect to QgsAttributeForm::featureSaved() only
after OK is clicked!
Best
Stefanos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20240110/66776eee/attachment.htm>
More information about the QGIS-Developer
mailing list