I'm setting up a custom widget in a QGIS3 plugin and include a QgsAttributeTableView like this:
layer = iface.activeLayer()
layer.getFeatures()
canvas = iface.mapCanvas()
vector_layer_cache = QgsVectorLayerCache(layer, 10000)
attribute_table_model = QgsAttributeTableModel(vector_layer_cache)
attribute_table_model.loadLayer()
attribute_table_filter_model = QgsAttributeTableFilterModel(canvas, attribute_table_model)
self.attribute_table_view = QgsAttributeTableView()
self.attribute_table_view.setModel(attribute_table_filter_model)
print("GIS-Layer: "+str(layer.allFeatureIds()))
self.layTab.addWidget(self.attribute_table_view)
But no data is shown in the QgsAttributeTableView. The print-output displays the list of all feature-ids of the loaded layer. So I think there are features, but not shown in my QgsAttributeTableView.
Answer
This works OK for me. It's possible that your issue is attribute_table_model going out of scope and being deleted, leaving no model to power the table view. But that's tricky to diagnose without seeing more of your code. I'd try changing attribute_table_model to be a member of self
, just like your view is.
No comments:
Post a Comment