Skip to content

Instantly share code, notes, and snippets.

@jcfr
Last active September 21, 2023 18:44
Show Gist options
  • Save jcfr/0251444ef8567c6882cc6701e22eb5af to your computer and use it in GitHub Desktop.
Save jcfr/0251444ef8567c6882cc6701e22eb5af to your computer and use it in GitHub Desktop.
Block Slicer shortcuts except specific ones
class CustomAppShortcutBlocker(qt.QObject):
def eventFilter(self, object, event):
"""
Custom event filter for allowing only specific shortcuts.
"""
# See https://doc.qt.io/qt-5/qkeyevent.html#details
if event.type() == qt.QEvent.Shortcut:
# Only allow showing/hiding "Error log"
if event.key() == qt.QKeySequence("Ctrl+0"):
return False
return True
if event.type() == qt.QEvent.ShortcutOverride:
return True
return False
shortcutBlocker = CustomAppShortcutBlocker()
slicer.app.installEventFilter(shortcutBlocker)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment