I need to create a custom table attribute inside a plugin where I can choose which layer I need to open and add new custom buttons to this custom table attribute
To become like this :
I need to create a custom table attribute inside a plugin where I can choose which layer I need to open and add new custom buttons to this custom table attribute
To become like this :
Have a look at QgsAttributeTableView and QgsAttributeTableModel classes. These are used by QGIS to display the attribute table.
I've put together a small example script which shows the attribute table of a vector layer in a small custom dialog. Instead of the label you can insert any desired other elements into the layout.
class MyWindow(QDialog):
def __init__(self, parent, canvas, layer):
super().__init__(parent)
layout = QVBoxLayout()
label = QLabel('Custom Widget')
layout.addWidget(label)
self.tableView = QgsAttributeTableView(self)
self.layerCache = QgsVectorLayerCache(layer, layer.featureCount())
self.tableModel = QgsAttributeTableModel(self.layerCache)
self.tableModel.loadLayer()
self.tableFilterModel = QgsAttributeTableFilterModel(canvas, self.tableModel, parent=self.tableModel)
self.tableFilterModel.setFilterMode(QgsAttributeTableFilterModel.ShowAll)
self.tableView.setModel(self.tableFilterModel)
layout.addWidget(self.tableView)
self.setLayout(layout)
layer = iface.activeLayer()
dlg = MyWindow(iface.mainWindow(), iface.mapCanvas(), layer)
dlg.show()
QgsAttributeTableDialogclass, which is not exposed through the python API. So I guess your only option would be to recreate those actions in python based on the original source file – CodeBard Mar 01 '22 at 16:02