5

I have a problem with the export of QGIS 3 interface screenshots. I run stand-alone scripts and one of them launches QGIS and runs script.py with the following code :

mapCanvas = iface.mapCanvas()

selectedfeatures= layer.getFeatures(QgsFeatureRequest(request))

for feat in selectedfeatures:
    layer.selectByIds([feat.id()])
    mapCanvas.zoomToSelected(layer)
    mapCanvas.refresh()
    mapCanvas.saveAsImage(path)

with the command line : qgis-bin.exe --nologo --project path_project --code script.py

But the images are not always saved (random files are saved, sometimes nothing), only the .pgw like if the interface had no time to refresh... I already read solutions like with refresh SLOTS, or QTimer but it doesn't work for me.

dmjf08
  • 1,263
  • 7
  • 16
  • Asimilar question was already answer for QGIS v2.x. Have you already tried such solution? https://gis.stackexchange.com/a/189825/4972 – Germán Carrillo Aug 27 '18 at 19:09
  • Yes as I explain it in my question the QTimer solution doesn't work for me. Thank you for your reply. – dmjf08 Aug 28 '18 at 08:22

1 Answers1

2

For people who want to know the answer, the difficulty for me was to use mapCanvasRefreshed() correctly. You have to initialize the process with a zoomToFeatureIds so that the signal is sent to your main function.

dmjf08
  • 1,263
  • 7
  • 16