Bug report #7283

saveAsImage not including entire mapCanvas

Added by Brian Edmond over 7 years ago. Updated about 2 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Map Canvas
Affected QGIS version:1.8.0 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:not reproducable
Crashes QGIS or corrupts data:No Copied to github as #:16293

Description

I have a plugin for exporting maps as PNG images. I believe this code was working correctly within 1.6 (but I cannot guarantee I haven't made another change that would have broken it there, too).

Basically, I load a set of base map features and then loop through a set of point layers that get applied and the whole thing is exported as an image. I'm not getting the full canvas at all, but only a single attribute loaded from the base map and nothing from the point layers. (bad result, expected result)

In the process of debugging this, I discovered a curious fact. If I include a QMessageBox.information right before I do the export, it works correctly!

Doesn't work:

self.mapCanvas.resize(QSize(394,350))
self.mapCanvas.zoomToFullExtent()
currentImagePath = theExportPath + folder
currentImageName = attribute.replace(' ', '_') + ".png"
self.mapCanvas.saveAsImage(currentImagePath + "/" + currentImageName)
Does work:
self.mapCanvas.resize(QSize(394,350))
self.mapCanvas.zoomToFullExtent()
QMessageBox.information(self.iface.mainWindow(),"Debug","Break")
currentImagePath = theExportPath + folder
currentImageName = attribute.replace(' ', '_') + ".png"
self.mapCanvas.saveAsImage(currentImagePath + "/" + currentImageName)

I tried to add a simple self.iface.mainWindow() in place of the message box but that didn't do the trick. I'm thinking there is some kind of refresh I could do, too, but I tried mapCanvas.refresh() and mapCanvas.updateMap() and these in combination with mainWindow() but could get nothing to work.

Did this change in 1.8? Any suggestions to make it work? Including the QMessageBox call will get me going but I have to press "OK" for each map to be exported. With all the export combinations, I'd be doing this more than 1000 times!

Thanks!

B

Reported as question at: http://gis.stackexchange.com/questions/52563/mapcanvas-saveasimage-not-functioning-as-expected-in-qgis-1-8

History

#1 Updated by Giovanni Manghi over 3 years ago

  • Easy fix? set to No
  • Regression? set to No

#2 Updated by Giovanni Manghi over 2 years ago

  • Status changed from Open to Feedback

Please test with a recent QGIS release (2.18 or 3), if the issue/request is still valid change the affected version accordingly, if is fixed/implemented then close the ticket. Thanks!

#3 Updated by Giovanni Manghi about 2 years ago

  • Resolution set to not reproducable
  • Status changed from Feedback to Closed
  • Description updated (diff)

Closing for lack of feedback.

Also available in: Atom PDF