I'm attempting to create a plugin in QGIS 3 in order to zoom on a selected feature and get the map picture exported in .jpg
format.
I've been able to perform the zoom and selection of my selection, and now I want to add some color border to the selected feature using QgsHightlight
:
def highlight_features():
for i in couche_parcelles.selectedFeatures():
h = QgsHighlight(canvas,i.geometry(),couche_parcelles)
h.setColor(QColor(255,0,0))
h.setWidth(10)
#================================Map Creation==================================
#project = QgsProject.instance()
mapSettings = canvas.mapSettings()
mapSettings.setOutputSize(QSize(1600,1100))
mapSettings.setOutputDpi(200)
render = QgsMapRendererSequentialJob(mapSettings)
render.start()
render.waitForFinished()
dir = r"C:\Users\[...]\Desktop"
img = render.renderedImage()
img.save(dir + "/" + "selection.jpg",'jpg')
It does make a pretty highlight border on QGIS software like this :
But then, once I get the map rendered, here's what I get generated by the script :
My question is, how can I get the highlight extracted with my selection on the map ? Because I'm not sure it has something to do with my canvas and I don't know if it's possible to embed my QgsHighlight in my canvas either
I've already seen this answer : Setting selection color transparent and border color red using PyQGIS? Which helped me to get the highlight on my selection borders but I can't figure out how to integrate it in my map rendering