4

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. enter image description here

5
  • It looks like a bug. What is QGIS full version, like QGIS 3.xx.x ? Apr 26, 2021 at 4:03
  • You create a LayoutFrame from a table, and then add the frame to the table (which is already in the frame)? Is that right?
    – wingnut
    Apr 26, 2021 at 8:03
  • I use QGIS 3.10 A Corunia... I went step by step through the script and find out that the code line[table.setColumns(cols)] caused the crash... the frame is drawn correctly if I delete that Code line... I found out that the Class QgsLayoutItemTextTable has no attribute ".setColumn"... Still looking for a clue... Thx for all
    – Rid El Mou
    Apr 26, 2021 at 17:58
  • 2
    Your script works as expected in QGIS v3.18.1. Apr 26, 2021 at 18:46
  • Thank you, I just upgraded to the last version of QGIS 3.18.2. It's working fine.
    – Rid El Mou
    Apr 26, 2021 at 20:29

1 Answer 1

1

thanks to @KadirŞahbaz. It was question of upgrading to newest version of QGIS.

enter image description here

1
  • What is the name of this Plugin? I want to try it when it will be released.
    – KVO
    Jul 11, 2021 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.