Zoom to Extent of a QgsVectorLayer Using PyQGIS

layerspyqgisqgis

Anyone know how to zoom to the extent of a Vectorlayer in QGIS using python plugin?

Best Answer

You'd get the app's Map Canvas and set its extent.

canvas = qgis.utils.iface.mapCanvas()
canvas.setExtent(layer.extent())

You might want to read this tutorial.