Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking to create an attribute table where the first field is a drop-down menu (I have achieved this by using the 'value map' edit widget), but I'm struggling to find a method for the next part;

After the value has been selected from the drop-down menu, I would like the adjacent cell (in the next field) to be automatically populated according to the value in the drop-down menu. So for example; if drop-down value = A, then adjacent field = 1. Or if drop-down value = B, then adjacent field value = 3, etc.

I realise that by using field calculator, it is possible to auto-populate fields as part of a separate process, but I would like to have the fields populated at the same time as the drop-down value is selected if possible.

I am using windows 7 and QGIS version 1.8.

Many thanks.

share|improve this question
up vote 7 down vote accepted

You will need a little python to do this.

You can read this very nice blog post here

Create a script similar to the following called and place it next to your project

from PyQt4.QtCore import *
from PyQt4.QtGui import *

aField = None
bField = None

def formOpen(dialog,layerid,featureid):
    global aField
    aField = dialog.findChild(QComboBox,"fieldA")
    global bField
    bField = dialog.findChild(QLineEdit,"fieldB")
    aField.currentIndexChanged.connect( aChanged )

def aChanged( value ):
    if ( aField.currentText() == 'A' )
        bField.setText( '1' )
    elif ( aField.currentText() == 'B' )
        bField.setText( '2' )

Go to Vector Layer Properties => General and enter FormFill.formOpen in the Init function line edit.

share|improve this answer
Is it possible to do it in qgis 2.10? Is there many differences of 1.8? – Diogo Caribé Oct 16 '15 at 19:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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