I am working on a Plugin that allows users to look for a feature in the database, select it, and then open the Layout designer with map, arrow legend and some labels.
I am looking to add a table that contains the selected feature coordinates if someone could help.
I already tried the code given here: Adding QgsLayoutItemTextTable to Print Layout
Once the script executed, the Layout designer opened and QGIS crashes and shut down
NB : When I delete the last line, the layout is created. But when I open it manualy. QGIS crashes.
project = QgsProject.instance()
layout = QgsPrintLayout(project)
layout.initializeDefaults()
table = QgsLayoutItemTextTable(layout)
layout.addMultiFrame(table)
# Add columns
cols = [QgsLayoutTableColumn(),QgsLayoutTableColumn(),QgsLayoutTableColumn()]
cols[0].setHeading("heading 0")
cols[1].setHeading("heading 1")
cols[2].setHeading("heading 2")
table.setColumns(cols)
#Add only 1 row
table.setContents([['hello', 'world', '!']])
#Base class for frame items, which form a layout multiframe item.
frame = QgsLayoutFrame(layout, table)
frame.attemptResize(QgsLayoutSize(30, 30), True)
table.addFrame(frame)
# Open the layout designerfor preview
iface.openLayoutDesigner(layout)
After I deleted the #Add columns section from the code below :
the frame is added and the layout designer opened
But the frame is shrinked and the row isn't displayed.