setHeaderData not working in a QgsAttributeTableModel?

المشرف العام

Administrator
طاقم الإدارة
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 mylayer_id)

from PyQt4.QtCore import Qtfrom PyQt4.QtGui import QTableViewfrom qgis.gui import QgsAttributeTableModellayer = 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



أكثر...
 
أعلى