I want to embed a layer table in a plugin but it's not only for viewing but also for editing.

My current code below displays the content

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import QgsVectorLayerCache
from qgis.gui import QgsAttributeTableView, QgsAttributeTableModel

layer_a = iface.activeLayer()
cache = QgsVectorLayerCache(layer_a, 10000)
model = QgsAttributeTableModel(cache)
new_view = QTableView()


When I activate editing mode for the layer, I'm able to get the caption and change content but it does not persist after a "Return" to validate.

It seems I wrongly expect the sync between my current table and the content attached to the layer. I suppose it's due to the cache. Any idea how can I sync both QtableView (native and mine)? Inserting the view from the table could be also a solution but I'm not sure it's possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.