[GIS] How to set QGIS map canvas size programmatically

extentsmapcanvaspyqgispythonqgis

I need my map canvas to be exactly 1920×1080. So the Save as image would save a png exactly this size.
I've tried setting it with

iface.mapCanvas.resize(QSize(1920,1080))

But no luck, resize() seems to be deprecated.
I'm using QGIS 2.16.0.

I'd also like to set map extent programmatically, if that's related.
Unfortunately, using composer is not an option here.

Best Answer

You can use the following to resize the map canvas:

from PyQt4.QtCore import QSize
iface.mapCanvas().resize(QSize(1920,1080))

You need to import QSize before being able to use it. Although you seem to be correct in that it was depreciated.