According to the latest official QGIS 3.X API reference there is a class that should insert attribute table of a layer. I tried to do it, but got an error. Here is a piece of code I used:

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from qgis.core import *
from qgis.gui import *

project = QgsProject.instance()
manager = project.layoutManager()
layout = QgsPrintLayout(project)
itemMap = QgsLayoutItemMap.create(layout)
tbl = QgsLayoutItemAttributeTable.create(layout)
layer_attr =  QgsProject.instance().mapLayersByName(u'buildings')[0]

And after the last line I get an error

TypeError: QgsLayout.addLayoutItem(): argument 1 has unexpected type 'QgsLayoutItemAttributeTable'

Can't understand why it is happening because QgsLayoutItemAttributeTable logically should be supported by layout methods. Main things in my code were taken from this question.

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.