I am working on a PyQGIS script where I allow the user to add features using the addFeature() map tool, where the user can create the geometry of the feature by clicking on the canvas, and after the geometry has been created, the user will be prompt up with a table where he can enter the attributes of the feature.

The question is, some attributes of the feature should be pre-defined, and some can be entered by the user. I found out that by using the following code I can suppress the prompt.


But I still want the user to be able to enter most of the attributes after the new feature has been added, so it is not a good solution.

Is there another way where I can define some attributes after the feature has been added, and then prompt the table? In that way, the pre-defined value should be shown in the table when it is opened, so the user does not have to give value to them again.

1 Answer 1


There are a couple of options here by configuration or by script:

Script - use the layer changeAttributeValue() method to set values before the table opens, see How to change the value of an attribute using QgsFeature in PyQGIS?

Configuration - set layer default value through Properties, see How to set a default value for attributes in shapefiles?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.