6

I wonder how to add a fixed table into QGIS layout.

I've tried this solution but it doesn't work :

model = MyOwnQgsFeatureFilterModel(layout)
tableEnsemble = QgsLayoutFrame(layout, model)
tableEnsemble.attemptMove(QgsLayoutPoint(float(tblEnsbl.minX), float(tblEnsbl.minY), QgsUnitTypes.LayoutMillimeters))
tableEnsemble.attemptResize(QgsLayoutSize(float(tblEnsbl.maxX), float(tblEnsbl.maxY), QgsUnitTypes.LayoutMillimeters))
layout.addLayoutItem(tableEnsemble)

I get an empty table like this "multiframe":

enter image description here

Instead, I want the table frame I created myself in the layout, not by code.

2
  • What is tblEnsbl? Sep 29, 2021 at 13:57
  • it's an object that i have it contains many numbers as string that i convert to float Sep 30, 2021 at 14:05

1 Answer 1

2

Late to the party but an answer


composerTitle = 'Layout 1'
project = QgsProject.instance()
projectLayoutManager = project.layoutManager()
# Access to the layout by name
layout = projectLayoutManager.layoutByName(composerTitle)

# Option 1: considering you selected the created table frame item in the GUI
tableEnsemble = layout.selectedLayoutItems()[0]

# Option 2: if you put an id to your manually created table frame item
tableEnsemble = layout.itemById('own_item')

# Then, change position of your manually created table now you got the reference
tableEnsemble.attemptMove(QgsLayoutPoint(float(tblEnsbl.minX), float(tblEnsbl.minY), QgsUnitTypes.LayoutMillimeters))
tableEnsemble.attemptResize(QgsLayoutSize(float(tblEnsbl.maxX), float(tblEnsbl.maxY), QgsUnitTypes.LayoutMillimeters))

Your Answer

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

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