We've built a qgis project for use in education and we want to set up a min. and max. zoom level (or scale) for the whole project.

In the project properties, we can specify some "project predefined scales", but this does not prevent from zooming over of these limits.

On each layer, we can set a min/max scale for rendering the layer (in Layer Properties > Rendering), but again, this only hides the layer when zooming over of these limits.

Is this feature available? Can we make it using some pyQGIS chunks of code?


You may try this solution

canvas = iface.mapCanvas()

# Disable mousewheel if you want
# QSettings().setValue("/qgis/zoom_factor", 1)

minScale = 10000000
maxScale = 90000000

def renderStart():
    scale = canvas.scale()
    if scale < minScale:
    if scale > maxScale:
    if scale < minScale or scale > maxScale:
        iface.actionPan().trigger() # Disable zoom in favor of pan


# canvas.renderStarting.disconnect(renderStart)
  • Nice thanks! The behaviour is not perfect since it still zoom in/out outside the limits and then quickly zoom at the min/maxScale, but that's better than nothing. – juminet Jun 15 '20 at 12:48
  • Yes, only cared about zoom here. You may look at gis.stackexchange.com/questions/153316/… and do some adaptation to achieve what you want (not only zoom/scale restriction but also extent restriction it seems) – ThomasG77 Jun 15 '20 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.