I have a vector layer, how to set defaults value in fields from the Python console.
Layer Properties / Attributes Form / Defaults |
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
You could make use of the
QgsDefaultValue class which allows you to enter default values or expressions for specific fields based on their index:
layer = iface.activeLayer() idx = layer.fields().indexFromName('ID') layer.setDefaultValueDefinition(idx, QgsDefaultValue('3*4'))