1

I'm trying to print out a map from Python console. The issue is that when I add a layer to the map composer, the property of the map is set to cache. However, I want to change it to render so that the map would look less blurry.

Below is my code to add a layer to the map composer:

map_settings = iface.mapCanvas().mapSettings()
c = QgsComposition(map_settings)

view = iface.createNewComposer()
view.setComposition(c)

composerMap = QgsComposerMap(c, 10 ,10, 160, 20)
composerMap.setBackgroundEnabled(True)

rect = QgsRectangle(map_settings.fullExtent())
composerMap.setNewExtent(rect)
composerMap.updateItem()
c.addComposerMap(composerMap)

I am wondering if there is any way to set the main property of map as render instead of cache from Python console.

0

You could set it using QgsComposerMap::setPreviewMode():

composerMap.setPreviewMode(0)
# 0 = cache
# 1 = render
# 2 = rectangle
  • @ryurruuggbbyy - Most welcome, glad it helped :) – Joseph Nov 20 '18 at 14:39

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.