Creating custom forms in QGIS – Part 2

Better late than never they say…

Anyway, on the previous post I explained how to customize the QGIS edit form using the available widgets depending on your attribute data types. In this post I will continue on how to further customize your form using the Drag and Drop Designer in QGIS (form layouts may look slightly different from the previous post as I now use QGIS 2.2 version).

Open the Layer properties form, click on the Field properties and select [Drag and Drop Designer] from the [Attribute editor Layout] drop down:


To create your custom dialog, you first need to create a ‘category’ i.e. a tab. So  click on the green ‘+’ button and add the label that will appear on your tab.


Now you can start adding fields inside this tab using the right blue arrow. Make sure you highligted the attributes you want to add AS WELL AS the tab name in the right panel for the arrow to get enabled.


You can add more tabs and fields repeating the steps above, as shown in the following screenshot:


And the completed form should now look like this:

The Streets attributes and Photo tabs…


…and the Website tab


Pretty simple- right?



Creating custom forms in QGIS – Part 1

One of the things I love about QGIS is its ability to easily create custom forms. Usually without writing a single line of code. The QGIS manual in my opinion doesn’t do it justice, as it only describes this functionality very briefly, so I decided to write a couple of posts explaining the process with examples.

I will be using a shapefile containing a road network. The attributes in the shapefile are as below and there are pretty self-explanatory:


Now, note the [Edit Widget] field. Its default value for each attribute is “Line Edit” which basically means it will display a simple text box for the user to enter a value when in Edit Mode. Obviously, this is not ideal as we got values like number of Lanes (LANES attribute) which should be numeric values or dates (DATE_OPEN attribute). QGIS won’t validate the form values till after we press the save button.

So first thing we need to do is change the widget (control) that will display in the Edit form for the DATE_OPEN attribute. Press the [Line Edit] button for this attribute and the attribute edit dialog will open. Select [Calendar] from the left panel:


You can edit the date format to control how the date will be displayed. When finished click the OK button.

Next, I wanted the ROAD_CLASS attribute to be selected from a drop-down list. To do this, follow the previous steps for the ROAD_CLASS attribute and this time select [Unique Values] as the widget. The Unique values widget will display all unique values that already exist in the shapefile in a drop-down list. And as we also need to be able to enter new values, check the [Editable] check box (the second one- the first is checked by default and it controls whether the field would be editable or not in edit mode).


Similary the Road environment (ROAD_ENVIR attribute) should be displayed as a drop-down list but this time we will use our own values. To do this select the [Value Map] widget and enter your values in the displayed grid as shown below:


Then, for the LANES attribute we would use the [Edit Range] widget. Number of lanes can range theoretically between 1 and 6, so put these values as min, max and define a step of 1:


But we can also display images or web pages in our form. Not surprisingly the photo widget is called [Photo] and you can defined the width and height of the image to display…


…whereas to display a web page of specific width and height you select the [Webview] widget:



You can also display a color ramp in your form. To do this, use the [SYMBOL] field in this example and select the [Color] widget:


If you followed this far, congratulations! Now close the properties window and start editing. Click on the identify button and click on any of the features in your shapefile. In the identify window right-click on one of the features and select the [Edit Feature Form] option:



Have a look at the form and note how the different fields display different widgets/controls based on wh

at we set them at, in the previous steps


As some of you may have noticed by now, this is not all the widgets that are available in QGIS but hopefully we covered quite a few of them and you got the general idea.

But this is not all. With QGIS, you can further customize your forms, adding tabs and grouping your controls. That’ll be next, in Part 2