[Qgis-developer] setting QgsMapCanvas size, for testing map tools

Tom Chadwin tom.chadwin at nnpa.org.uk
Fri Jul 1 04:08:32 PDT 2016


Barry Rowlingson wrote
> Maybe I've missed something here, but doesn't the canvas resize method
> set the canvas pixel size? This behaves as expected when run
> standalone from a python prompt.
> 
> from qgis.core import *
> from qgis.gui import *
> app = QgsApplication([],True)
> canvas = QgsMapCanvas()
> canvas.show()
> canvas.resize(1000,200)
> canvas.resize(1000,1000)
> 
> Note the map canvas has no parent, so just appears on its own at the
> specified size.
> 
> Or maybe I've missed a point....

I don't want to misrepresent what Sandro is asking, but I think it's the
same as me. I think (and this is from memory), that we need to do this to
the QGIS app canvas instance, rather than a newly created one.

When I run canvas.resize() locally, it behaves as I expect. I can then run
qgis2web (this is my reason for wanting to solve this), to export a web map
of the same size as the canvas.

What I don't understand is that when testing under Travis, with the same
canvas.resize() in the test script, I get different bounds in the webmap to
what I get when resizing my client canvas and exporting.

This experience was a while ago, of course. Perhaps the qgis2web code has
evolved so that this now works - I'll look into it when I can. However, last
time around, it didn't work for me, hence my earlier message to this list.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/setting-QgsMapCanvas-size-for-testing-map-tools-tp5273987p5274351.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list