4

Using QGIS 3.10, I am attempting to move a legend in one layout to the same position as a legend in another layout. I just can't figure out how to get the X/Y position of the first legend.

project = QgsProject.instance()
projectLayoutManager = project.layoutManager()

layout1 = projectLayoutManager.layoutByName("layout1")
legend1 = layout1.itemById("legend")
x = (x position of legend?)
y = (y position of legend?)

layout2 = projectLayoutManager.layoutByName("layout2")
legend2 = layout2.itemById("legend")

legend2.attemptMove(QgsLayoutPoint(x,y,QgsUnitTypes.LayoutMillimeters))

1 Answer 1

5

I figured it out myself:

project = QgsProject.instance()
projectLayoutManager = project.layoutManager()

layout1 = projectLayoutManager.layoutByName("layout1")
legend1 = layout1.itemById("legend")
CurrentPositionPoint=legend1.positionWithUnits()

layout2 = projectLayoutManager.layoutByName("layout2")
legend2 = layout2.itemById("legend")
legend2.attemptMove(CurrentPositionPoint)

I found the answer here: QGIS API Documentation -->QgsLayoutItemLegend Class Reference -->Public Member Functions Inherited from QgsLayoutItem

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.