3

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.

  • Asimilar question was already answer for QGIS v2.x. Have you already tried such solution? 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 8:22
1

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.

  • Could you explain in greater detail? – Richard Aug 23 at 1:22

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.