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.
1 Answer 1
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)
-
Thanks it works now. Because i want this inside plugin, I added self before openLayoutDesigner.
self.iface.openLayoutDesigner(layout=l_out)
Wilho– Wilho2018年08月08日 08:56:20 +00:00Commented 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".etrimaille– etrimaille2021年08月20日 08:36:33 +00:00Commented Aug 20, 2021 at 8:36