I am writing a script that automatically generates a print layout. In addition to the map, the print layout should contain a table with results of a series of calculations that I have in the form of a python dictionary. While I have gotten into the workflow of adding layout items to the print layout,
QgsLayoutItemTextTable seems to work differently.
This works fine:
project = QgsProject.instance() layout = QgsPrintLayout(project) layout.initializeDefaults() title = QgsLayoutItemLabel(layout) title.setText('MyTitle') title.adjustSizeToText() layout.addLayoutItem(title)
QgsLayoutItemTextTable class, however, is for some reason not based on the
QgsLayoutItem class and therefore
project = QgsProject.instance() layout = QgsPrintLayout(project) layout.initializeDefaults() table = QgsLayoutItemTextTable(layout) table.addRow(['hello', 'world', '!']) layout.addLayoutItem(table)
results in the following error:
TypeError: QgsLayout.addLayoutItem(): argument 1 has unexpected type 'QgsLayoutItemTextTable'
Can anyone explain to me why this is the case and what is the intended workflow?