Is it possible to create "rotate canvas" shortcuts in QGIS? I'm thinking about something like "Ctrl + mouse scroll up" to rotate the canvas clockwise and "Ctrl + mouse scroll down" to rotate the canvas counter clockwise...


To rotate the canvas and assign a shortcut using Python, you could use something like the following which you could paste into the Python Console:

from PyQt4.QtGui import QShortcut, QKeySequence
from PyQt4.QtCore import Qt

def rot_clock():
    # Rotate clockwise by 10 degrees
    rot = qgis.utils.iface.mapCanvas().rotation()
    qgis.utils.iface.mapCanvas().setRotation(rot + 10)

def rot_anticlock():
    # Rotate anti-clockwise by 10 degrees
    rot = qgis.utils.iface.mapCanvas().rotation()
    qgis.utils.iface.mapCanvas().setRotation(rot - 10)

# Assign shortcut to "Ctrl + K"
rotate_clock = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_K), iface.mainWindow())

# Assign shortcut to "Ctrl + L"
rotate_anti = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_L), iface.mainWindow())

If you want to assign it to the mouse wheel, you could look into the QWheelEvent class and try to incorporate that into the code above.

  • The code works fine but I think that the Rotation widget should also be updated when using the shortcuts... how can this be implemented? – Bryan Ciceri Oct 13 '16 at 14:22
  • @BryanCiceri - Edited post which should now update the rotation widget =) – Joseph Oct 13 '16 at 15:00
  • I've just made some edits to the code so now it runs during the QGIS opening and the shortcuts behavior is similar to the Rotation widget one... the cherry on top would be to implement the mouse wheel... – Bryan Ciceri Oct 13 '16 at 16:53

There's similar functionality, in QGIS 2.16.3, at least.

Hover your mouse over the Rotation widget at the bottom of the screen, and roll the mouse up or down...

rotate canvas widget

  • roll up or down to rotate in 5 degree steps (up=clockwise, down=counter-clockwise)
  • Hold Shift and roll for 50 degree steps

I can't see a way to do this when hovering over the canvas, as Settings > Configure Shortcuts doesn't include the rotate widget as a target, and the dialog only seems to support keyboard combinations. It might be possible using Python but not looked into that.

  • I actually change the rotation degrees by hovering the widget, exactly as you described, but I'm searching for a way to do it while hovering the canvas as it would be really time-saving in some cases... – Bryan Ciceri Oct 12 '16 at 20:52

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.