Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

1 Answer 1

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 FillForm.py 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

Your Answer

 
discard

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.