Segment Editor shortcurts does not work

Hi to everyone :slight_smile:

Today I’m looking for the command to activate and deactivate the segment Editor shortcuts using Python code. The shortcuts sometimes works correctly and then, in the same conditions if I open again the segmentation they doesn’t work anymore.

Can I anybody explain me how this works, and if it’s possible to activate and deactivate it?

Thanks a lot.

Management of shortcuts in Qt is quite complex and fragile. Most often shortcuts break when you are trying to assign a shortcut multiple times. Make sure that after calling installKeyboardShortcuts you always call uninstallKeyboardShortcuts.

1 Like

Hi @lassoan, could you please elaborate what you meant here?

Like @SANTIAGO_PENDON_MING tried, I was also disabling the shortcut “Ctrl+Z” with custom logic using -

def disableShortcut(sequence: str):
    shortcut = qt.QShortcut(slicer.util.mainWindow())
    shortcut.setKey(qt.QKeySequence(sequence))
    shortcut.connect("activated()", lambda: None)

After disabling the shortcut once, if I restart the application with the calls to this function removed( therefore no more “Ctrl+z” shortcut override), I am not able to use the shortcut for the segment editor. Like @SANTIAGO_PENDON_MING mentioned, the shortcut doesn’t work anymore. Would you happen to know why?

Found this in another post as well :-

So are you suggesting that I should not disable “Ctrl+z“ based on custom logic?