I´m setting up an database for an archaeological project with PSQL. There I have a field "material" connected with a table "materials" containing things like metal, stone, etc. In a third table I have stored more specific data on the materials like "gold", "iron" or "tuff". They all cary an attribute to which material they belong.

Now I set up a custom form in QGIS which works quite well. But now to my problem: I want to choose a material in the first combobox and the specification in a second one. The entries of that field should be filtered by the first one. So when I choose "metal" in the first field the second field should just show me iron, gold and copper.


First i would create a list of categories and a dictionary containing the categories and related specific material like

self.cat_list = ['metal', 'stone', 'wood']
self.mat_dict = {'metal':['gold', 'iron', 'copper'],
       'stone':['flint', 'granite', 'wackestone']}

and so on.

Consider you comboBoxes are




populate the first combo with cat_list and connect a method that dependently populates the second:

for c in self.cat_list:

#updateMatlist is the function called when a category is selected

now implement the method mentioned above

def updateMatlist(self):
    #empty list
    for n in range(self.comboBox_mat.count()):
    #repopulate combo
    for mat in self.mat_dict[self.comboBox_category.currentText()]:

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