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.
iface.showAttributeTable(iface.activeLayer)
2 Answers 2
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)
model.loadLayer()
table = QTableView()
table.setModel(model)
-
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– Dil2014年06月19日 06:15:57 +00:00Commented Jun 19, 2014 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– Barbarossa2016年08月25日 20:33:35 +00:00Commented Aug 25, 2016 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:
self.ui.listWidget.addItem(i.name())
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– Nathan W2014年06月18日 11:54:45 +00:00Commented Jun 18, 2014 at 11:54