I'm trying to learn a little bit of Python in QGIS with the following tutorial: QGIS Maprendering.
Now the tutorial works, with minor adjustments. In QGIS I have four layers, and one them is showing labels (country names), but when I export to PNG or PDF the labels of the layer won't show in the output file.
My code:
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
import processing
from qgis.PyQt.QtCore import *
img = QImage(QSize(1200, 1000), QImage.Format_ARGB32_Premultiplied)
color = QColor(250, 250, 250)
img.fill(color.rgb())
p = QPainter()
p.begin(img)
p.setRenderHint(QPainter.Antialiasing)
render = QgsMapRenderer()
layers = iface.mapCanvas().layers()
print layers
layers_ids = []
for layer in layers:
print layer.id()
layers_ids.append(layer.id())
render.setLayerSet(layers_ids)
rect = QgsRectangle((iface.mapCanvas().extent().xMinimum()),(iface.mapCanvas().extent().yMinimum()),(iface.mapCanvas().extent().xMaximum()),(iface.mapCanvas().extent().yMaximum()))
rect.scale(1.1)
render.setExtent(rect)
render.setOutputSize(img.size(), img.logicalDpiX())
render.render(p)
p.end()
img.save("map2.png","png")
Is there anyone who can help me with this problem?