I want to customize attributes form in QGIS 3.6 with a combo box which will fill with a predefined value.

I found on the web examples but with the version 2.x or with Python code. This last solution doesn't seem to work very fine.

Is there a simple way to associate a field with a combo box?


A simple way to do this is to use the Value Map widget type. Open the layer properties dialog for the layer you are working on and click on the Form tab on the left hand side. Select the field which you want to associate with the combo box and change the widget type to value map. You can either populate the combo box with values from a field in any layer loaded in the layers panel, or from a saved csv file. Now, with the layer in edit mode, the edit widget for the chosen field in the feature form will be a combo box populated with your custom values. See screenshots below of layer properties settings and resulting feature form.

enter image description here

enter image description here

If you want take it a step further, you can create a ui file in Qt Designer and use this as your feature editing form. The trick is to make sure that, in Designer, you give your widget objects exactly the same name as the fields to which you want to bind them. Save the ui file in the same directory as your QGIS project file. Then go back into the Form tab in layer properties; change the Attribute layout editor from Autogenerate to Provide ui-file, then under Edit UI, load the ui file by browsing to its location. See screenshot below:

enter image description here

With this workflow, you have a lot more control over feature editing- for example you can include widgets for only a subset of fields (if you want to limit or simplify editing for users) and you have more options for customizing widget types.

In the example below, I have a layer of plant records and have created a ui form with edit widgets for four fields. For Taxon_Name I am using the value map widget type with a combo box which is populated from values in a csv layer.

enter image description here

enter image description here

  • Thanks a lot for your very detailed answer ! – vcloarec Mar 29 '19 at 13:44

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.