Last active
September 21, 2023 18:44
-
-
Save jcfr/0251444ef8567c6882cc6701e22eb5af to your computer and use it in GitHub Desktop.
Block Slicer shortcuts except specific ones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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