1

I have a list of vector layers loaded in the canvas of qgis.

  `layers = self.iface.mapCanvas().layers()
    for layer in layers:
        if layer.type() == QgsMapLayer.VectorLayer:
            self.dlg.featurecombo.addItem( layer.name(), layer )`

The above snippets of code can be used to display all the layers in the popdown box of the plugin. But it wont load all layers instead it gives results for one layer.(for example, if I have 3 layers loaded and I want a feature count for layers, it will display all 3 layers in the popdown down box but the above snippet will show the feature count for one layer It would be more helpful if i can get a snippet to load all layers and display the result for all layers at a stretch.

  • It's unlikely you get proper answers from a question like this. You need to provide us with more context. What exactly you get now and what do you expect to get? – Germán Carrillo Feb 5 '15 at 3:44
2

If you want to show a combo box with a list of layers don't reinvent the wheel instead you should use the QgsMapLayerComboBox class from the API

cmb = QgsMapLayerComboBox()

if you have a .ui you can promote a QComboBox using the following:

Header file: qgis.gui
Class name: QgsMapLayerComboBox
  • My combo box is listing all the layers. But I can select only one layer from the list in the combo box obviously my result would be for a single layer. I want to select all the layers listed in the combo box and display the result for all the layers within a single click. – User123 Feb 5 '15 at 5:19
  • A combnobox is only a single item at a time, you will need a ListWidget or ListView for a multiselect – Nathan W Feb 5 '15 at 5:20
  • Thank you for the response Nathan. I am new to qgis plugins. Can you brief more about ListWidget or ListView? or any links. – User123 Feb 5 '15 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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