I'm developing a QGIS plugin using QtDesigner and pyqt4. I have a comboBox of my vector layers and I want to show the table of the selected layer. I used this code for my comboBox:

def run(self):
    """Run method that performs all the real work"""

    allLayers = self.iface.legendInterface().layers()
    allLyrNames = [lyr.name() for lyr in allLayers]

    # show the dialog
    # Run the dialog event loop
    result = self.dlg.exec_()
    # See if OK was pressed
    if result:
        # Do something useful here - delete the line containing pass and
        # substitute with your code.

        grdLayerName = self.dlg.getGridLayer()


And these two functions:

def getGridLayer(self):
def updateCombos(self, items):
    if len(items) > 0:

        for item in items:

1 Answer 1


You can take a look at the bottom part sample from https://webgeodatavore.github.io/pyqgis-samples/gui-group/QgsAttributeTableView.html for a solution (disclosure: I'm the author of the content)

You may also look at https://webgeodatavore.github.io/pyqgis-samples/gui-group/QgsMapLayerComboBox.html for a component to select layers

Both samples are standalone: run them in the QGIS Python console after opening any QGIS project. You will need to change iface reference while integrating in a plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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