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.


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")
| improve this answer | |
  • Thanks it works now. Because i want this inside plugin, I added self before openLayoutDesigner. self.iface.openLayoutDesigner(layout=l_out) – Wilho Aug 8 '18 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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