Is there any way to show the attribute table of a layer in a QTextBrowser or a QTableView on form?

I did this but, (shows attribute table in a separate dialog) I have no idea, how to show it in my form.


QGIS 2.2 has a table model that you can use for a QTableView. Use it like this:

cache = QgsVectorLayerCache(layer, 10000)
model = QgsAttributeTableModel(cache)
table = QTableView()
  • Thank You for the answer. I tried this but it shows nothing. I'm very new to qgis and python,so I don't know what should I do to show the attribute table in my QTableView. Please help me to do it. – Dil Jun 19 '14 at 6:15
  • QGIS 2.16 crashes when trying to apply this to a plugin tableview. But it only crashes when I try to use .show() – Barbarossa Aug 25 '16 at 20:33

I am using a button to get current layers from canvas in my qgis2leaf plugin like this:

canvas = qgis.utils.iface.mapCanvas()
        allLayers = canvas.layers()
        for i in allLayers:
            if i.type() == 2:
                print(i.name() + " skipped as it is not a vector layer nor a raster layer")  
            if i.type() < 2: 

what you can do: do another loop over the layer and get all attributes. with

attributes = i.getFeatures()

and print them in another listwidget in your GUI.

  • The user wants to show the attribute table in their form not a list layers or features. – Nathan W Jun 18 '14 at 11:54

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.