0

I am developing a a plugin in QGIS. I want to add attribute table of a vector layer as data model in QTableView. I am using following lines of code but it is adding empty column.

    vector_layer_cache = QgsVectorLayerCache(select_op, 10000)     
    attribute_table_model = QgsAttributeTableModel(vector_layer_cache)
    attribute_table_model.loadLayer()
    self.dlg.tableView.setModel(attribute_table_model)

How to get full attribute table displayed in QTableView/QTableWidget?

vigna purohit
  • 441
  • 2
  • 12
  • QgsAttributeTableView.setModel() does not receive a parameter of type QgsAttributeTableModel but a QgsAttributeTableFilterModel instead, where you can set a filter to show all features. Look at https://gis.stackexchange.com/questions/425009/how-to-show-the-attribute-table-inside-the-dialogue-of-a-custom-plugin-with-qgis/425042 – CodeBard Mar 10 '22 at 08:18
  • That one gives the same output of empty columns.@CodeBard – vigna purohit Mar 10 '22 at 10:53
  • Did you try the exact same code from the answer I linked? Because that clearly works for me. You may need to set all the objects as instance variables instead of local variables, so self.attribute_table_model = instead of attribute_table_model = etc. – CodeBard Mar 10 '22 at 11:28

0 Answers0