I have trouble assigning function to a hotkey in my plugin. I have a class that does things with a mouse click. I'd like to assign another function to a keyboard key or sequence. I've tried two different approaches:
https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/snippets.html#how-to-call-a-method-by-a-key-shortcut This assigns given key sequence as a shortcut, but does nothing.
def scale(): iface.mapCanvas.zoomScale( 2500 ) shortcut = QShortcut(QKeySequence(Qt.ControlModifier + Qt.Key_Q), iface.mainWindow()) shortcut.setContext(Qt.ApplicationShortcut) shortcut.activated.connect(scale)
Both don't return any errors, but just doesn't work. I made sure that key sequences aren't in use. What am I missing?