I am developing a plugin in QGIS which involves the use of QgsFieldComboBox, what I want to do is that the combo box only shows fields(column names from attribute table), and from this QgsFieldComboBox i can select one field and then i wants to show features of that particular column in another combobox.
By using following code i unable to show feild names in combBox_2,and after selecting a particular field name unable to show features in comboBox_3.. please help.
def run(self):
"""Run method that performs all the real work"""
if self.first_start == True:
self.first_start = False
self.dlg = GetMapDialog()
# Connect signal to slot which will update comboBox_2 whenever selection in comboBox changes
self.dlg.comboBox.layerChanged.connect(self.my_combobox_2)
self.dlg.comboBox.layerChanged.connect(self.my_combobox_3)
self.dlg.comboBox_2.fieldChanged.connect(self.my_combobox_3
self.dlg.comboBox.setFilters(QgsMapLayerProxyModel.PolygonLayer)
#self.dlg.comboBox_2.setFilters(QgsFieldProxyModel.AllTypes)
self.my_combobox_2()
self.my_combobox_3()
# show the dialog
self.dlg.show()
def my_combobox_2(self):
self.dlg.comboBox_2.clear()
selectedLayer = self.dlg.comboBox.currentLayer()
#self.dlg.comboBox_2.addItems([field.name() for field in fields])
if selectedLayer:
self.dlg.comboBox_2.setFilters(QgsFieldProxyModel.AllTypes)
def my_combobox_3(self):
self.dlg.comboBox_3.clear()
selectedLayer = self.dlg.comboBox.currentLayer()
selectedField = self.dlg.comboBox_2.currentField()
featuredata=[]
for feature in selectedLayer.getFeatures():
featuredata.append(feature[selectedField])
self.dlg.comboBox_3.addItems(featuredata)