Is there a
Qgs dialog or widget that I can use in a standalone pyqgis application to open the attribute table of a
QgsVectorLayer? this seems to be such a simple thing, there has to be an existing widget or dialog...
Update: After some extensive search, there seem to be two ways to do this in pyqgis, neither worked well, I am just going to summarize them here:
Approach 1. use the
QgsDualView class as below:
self.editor = QgsDualView(self) self.editor.init(self.layer, self.map_control.canvas) self.editor.setView(QgsDualView.AttributeEditor)
This will display attributes as below:
Approach 2. use the
lyr_cache = QgsVectorLayerCache(self.layer, 120, self) tbl_model = QgsAttributeTableModel(lyr_cache, self) tbl_model.loadAttributes() tbl_model.loadLayer() tbl_filter_model = QgsAttributeTableFilterModel(self.map_control.canvas, tbl_model, self) self.editor = QgsAttributeTableView(self) self.editor.setModel(tbl_filter_model)
This will display as below:
So, as you can see, both look very much half-baked. I did accept @Matthias Kuhn's reply as answer as it did answer my original question, but in light of the fact that it didn't actually work, I continue to hope that someone can give suggestions that could make either approach work better. I will certainly up-vote your answers and give confirmation, this will benefit the larger community.