I am a beginner at PyQGIS.

I am trying to create a plugin, which will be used to Add, Delete, and Edit the Feature.

It is more customized than which is provided by QGIS (2.2).

I am capturing the Points using RubberBand API and then Add the attributes for the feature using openFeatureForm(). The openFeatureForm() takes default values as NULL.

What I want is to customize this form. Like, populate some values with a Combobox (to allow a user to select the required values). Also for fields like the date, I want to put DateTimePicker() widget in the form.

So Is it possible to customize the form provided by openFeatureForm()?


QGIS provides some UI widget types from the layer field config.

  • "Value Map" providing a combo box
  • "Date/Time" providing a date picker

To set these field widgets from Python, try this (pyqgis 2.18):

formConfig = layer.editFormConfig()
formConfig.setSuppress(False) # open edit form by default

i = layer.fields().indexFromName('combo-field')
formConfig.setNotNull(i, True) # input required
formConfig.setWidgetType(i, 'ValueMap')
formConfig.setWidgetConfig(i, {
    'label': 'fieldvalue',
    'label2': 'value2',

So for basic UI widgets you don't need to create a custom edit widget. However if you need to validate field inputs based on other fields, you should create a custom edit widget.

To explore the available fields, use the QGIS UI: In the Fields tab in the layer properties, you can set up certain input types for each field. enter image description here


For customize feature form you should make form in QtDesigner and set ui to you layer. https://qgis.org/api/2.2/classQgsVectorLayer.html#aed365f469a74156a577500bfdd0fdc80

example: my_vector_layer.setEditForm("C:/my_form.ui")

note: very important input widgets in form might have actually that name as in layer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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