Bug report #3420

QgsMapCanvas not rendering raster layers in QGIS 1.7

Added by goocreations - over 13 years ago. Updated over 13 years ago.

Status:Closed
Priority:Low
Assignee:Martin Dobias
Category:Map Canvas
Affected QGIS version: Regression?:No
Operating System:Debian Easy fix?:No
Pull Request or Patch supplied: Resolution:fixed
Crashes QGIS or corrupts data: Copied to github as #:13480

Description

I've found a problem when using the QgsMapCanvas in new version of QGIS which is not present in the previous version.

When using QgsMapCanvas in Python like this:

layer = [[QgsRasterLayer]](filePath, fileInfo.completeBaseName())
mapRegistry = [[QgsMapLayerRegistry]].instance().addMapLayer(layer, False)
layerSet = []
mapCanvasLayer = [[QgsMapCanvasLayer]](layer, True)
layerSet.append(mapCanvasLayer)
self.canvas.setExtent(layer.extent())
self.canvas.enableAntiAliasing(True)
self.canvas.freeze(False)
self.canvas.setLayerSet(layerSet)
self.canvas.setVisible(True)
self.canvas.refresh()

The debug console says the raster was render without issues, the extent was set correctly, but the raster is not showing on the canvas (MirrorMap python plugin has the problem too).

After working through the C++ source code of QgsMapCanvas, I've noticed that most of the resizeEvent's code is now in the paintEvent. For some reason repaint is not called once the canvas resizes, hence the code (previously in the resiveEvent) is never executed. The important part of the code is:

mMap->resize( QSize( width, height ) );

which when called renders the raster correctly. I've adapted the python code of my plug-in as follows:

layer = [[QgsRasterLayer]](filePath, fileInfo.completeBaseName())
mapRegistry = [[QgsMapLayerRegistry]].instance().addMapLayer(layer, False)
layerSet = []
mapCanvasLayer = [[QgsMapCanvasLayer]](layer, True)
layerSet.append(mapCanvasLayer)
self.canvas.setExtent(layer.extent())
self.canvas.enableAntiAliasing(True)
self.canvas.freeze(False)
self.canvas.setLayerSet(layerSet)
width = self.canvas.size().width() #NEW CODE
height = self.canvas.size().height() #NEW CODE
self.canvas.map().resize( QSize( width, height ) ) #NEW CODE
self.canvas.setVisible(True)
self.canvas.refresh()

Every time I add a raster layer to the canvas, I have to manually resize the map of the canvas.
I'm not sure if this is a bug, or if it has to be this way. Is there any other or better way doing this?

mapcanvaspatch.diff Magnifier - the possible solution (453 Bytes) goocreations -, 2011-01-24 10:53 PM

History

#1 Updated by goocreations - over 13 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

Hey here is a solution to this problem (hopefully). Just added the paintEvent to the Python bindings. I've attached a patch.

#2 Updated by Tim Sutton over 13 years ago

Applied with 43aff118 (SVN r15076).

Regards

Tim

Also available in: Atom PDF