[Qgis-developer] Opening composer from Python

Alexander Bruy alexander.bruy at gmail.com
Thu Oct 31 01:10:41 PDT 2013


Hi all,

I need to create composer window with prepared composition from Python.
There is an createNewComposer() method and seems this is what I need.

I run simple test from Python console and it works, but when I tried to use
same code from plugin QGIS crashes. Here is code for console:

canvas = iface.mapCanvas()
renderer = canvas.mapRenderer()
composition = QgsComposition(renderer)
composition.setPlotStyle(QgsComposition.Print)
composition.setPrintResolution(300)
composition.setPrintAsRaster(True)
map = QgsComposerMap(composition, 5, 5, 200, 200)
map.setNewExtent(canvas.currentLayer().extent())
composition.addItem(map)
c = iface.createNewComposer()
c.setComposition(composition)

Any ideas what can be wrong? Maybe I miss something obvious?

-- 
Alexander Bruy


More information about the Qgis-developer mailing list