3

Is it possible to open saved layout in layout designer(print composer) with Python?

QGIS Python API:

openLayoutDesigner(self, layout: QgsMasterLayoutInterface) → QgsLayoutDesignerInterface

Opens a new layout designer dialog for the specified layout, or brings an already open designer window to the foreground if one is already created for the layout.

New in version 3.0.

I have tried iface.openLayoutDesigner("layoutname") in python console, but I get error:

TypeError: QgisInterface.openLayoutDesigner(): argument 1 has unexpected type 'str'

I don't understand what argument 1 should be.

Noura
3,4373 gold badges21 silver badges41 bronze badges
asked Aug 7, 2018 at 11:17

1 Answer 1

6

You should get the layout to open, first. Then pass the layout instance to openLayoutDesigner() method. You can't open a layout by passing its name to that method. The method expect you to pass QgsMasterLayoutInterface instance.

Try in this way:

l_out = QgsProject.instance().layoutManager().layoutByName("layoutname")
iface.openLayoutDesigner(layout=l_out)
answered Aug 7, 2018 at 12:06
2
  • Thanks it works now. Because i want this inside plugin, I added self before openLayoutDesigner. self.iface.openLayoutDesigner(layout=l_out) Commented Aug 8, 2018 at 8:56
  • To have iface inside a plugin, you can do "from qgis.utils import iface". No need to always have it in "self". Commented Aug 20, 2021 at 8:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.