Geographic Information Systems Asked by V Damoy on January 27, 2021
With QGIS 2.18, I used to capture the composer closure with PyQGIS, the class QgsComposerView and its composerViewHide signal:
self.obj_compo.composerView.composerViewHide.connect(self.raiseModule)
Now, there is the QGIS 3 answer:
AttributeError: ‘composerClass’ object has no attribute ‘composerView’
I guess this is because "composer related methods have been removed from the public API and Python bindings. These classes have been replaced with the new layouts engine, based on QgsLayout
, QgsLayoutItem
, and the other related classes."
But I can’t find a signal in QgsLayout
class or a parent to capture the composer closure. If someone has any clues…
The QgisInterface
class has the following signals which you should be able to make work for you:
These signals will be emitted when any print layout is opened/closed etc. but the latter two also emit the QgsLayoutDesignerInterface
object which you can catch in a slot function. So, if you only want to target a specific layout you could do something like:
def layoutClosed(designer):
if designer.window().windowTitle() == 'Some layout name':
#Do something here
iface.layoutDesignerWillBeClosed.connect(layoutClosed)
The above is just an example which I tested in the Python console. It seems your code is inside a plugin so you will need to modify accordingly e.g. put the signal/slot connection inside the initGui(self)
method, and make iface and slot function instance attribute/ method etc.
To be honest, while this should work, it doesn't seem particularly elegant but I can't readily see a better solution. If someone knows a better way- I will be glad to learn it.
Correct answer by Ben W on January 27, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP