[Qgis-developer] Can not Run function when item selected in comboBox

Luís Miguel Royo Pérez luis.miguel.royo at gmail.com
Sun Mar 6 23:41:25 PST 2016


Dear list,

I'm writing a plugin, I want to change the content of a comboBox 
(fields) depending of the content of another comboBox (layers).

My plugin is a dockwidget. I can populate the fields comboBox just 
starting the plugin in the /def run(self):/ function, and it's working fine:

|layerNom =self.dockwidget.comboBoxErrores.currentText() #Getthe text 
value of the comboBox forlyr 
inQgsMapLayerRegistry.instance().mapLayers().values():#Get layers 
iflyr.name()==str(layerNom):fields =lyr.pendingFields()#Get 
Fielsfield_names =[field.name()forfield infields]#Field 
Listself.dockwidget.comboCampos.addItems(field_names)#Add to the comboBox|

But when I try to update the content of the fields comboBox I really 
don't know how to do it.

In my "pluginName_dockwidget.py" file, in the *init* function I have 
created the connection with the function that will repopulate the 
comboBox with the new content:

|self.comboBoxErrores.currentIndexChanged['QString'].connect(self.pueblaCampos)|

In the same file I have a function that get the value of the layer name 
of the comboBox and emit it with the signal created previously:

|sennalComboIndex =pyqtSignal(str)...defpueblaCampos(self):layerName 
=self.comboBoxErrores.currentText()self.sennalComboIndex.emit(layerName)|

In my main file, I have the rest of the function:

|defpueblaCampos(self,layerName):forlyr 
inQgsMapLayerRegistry.instance().mapLayers().values():iflyr.name()==str(layerName):fields 
=lyr.pendingFields()field_names =[field.name()forfield 
infields]self.dockwidget.comboCampos.clear()self.dockwidget.comboCampos.addItems(field_names)|

When I change the slected item in the layers comboBox, nothing happens. 
What Am I missing?

Ask for more detail info if you think it's needed. Thank you very much!!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160307/8e208abe/attachment-0001.html>


More information about the Qgis-developer mailing list