I want to display the content from a layer in a new view
I have so far a code like below (you should have 2 columns at least, then, just try in the QGIS Python console replacing
from PyQt4.QtCore import Qt from PyQt4.QtGui import QTableView from qgis.gui import QgsAttributeTableModel layer = QgsMapLayerRegistry.instance().mapLayer(u'mylayer_id') cache = QgsVectorLayerCache(layer, 10000) model = QgsAttributeTableModel(cache) print model.setHeaderData(0, Qt.Horizontal, u"pk") print model.setHeaderData(1, Qt.Horizontal, u"name") model.loadLayer() table = QTableView() table.setModel(model) table.show()
The problem is the fact that header in the view are not updated with
model.setHeaderData: it returns
false (meaning that the header was not updated) whereas with other models (from Qt), I don't encounter this issue.
You may wonder why I make a reference to other Qt models? It's because the
setHeaderData method is inherited from Qt QAbstractItemModel.
Is is due to the QGIS cache? How can I solve this issue? Any hints is welcome