Customize mouse button function

Operating system: Win10
Slicer version: 4.9.0
Expected behavior: Is it possible to change the default function of the mouse buttons? In my clinical software right click and drag scrolls through the volume, while in 3Dslicer it zooms. Would be great to be able to change these presets, rather than having to get used to several different interfaces. Like wise, left-click and drag changes the windowing - which I hate because once I find a window that I’m happy with I generally don’t want it to change!

1 Like

Hi -

Right now these functions are hard coded in the interactor style code. It Should be possible to override this behavior with some python scripting, but there’s no GUI for it. If you are interested in doing some programming let us know if you want ideas of how to get started.

One thing that you can do is lock the window/level for a Volume using the Volumes Module. Not exactly what you asked for but it might help.

Best,
Steve

Just a suggestion for future feature: to have number of customizations as themes that makes the interface looks and behaves similar to popular tools. I know some radiologists who do not like to use Slicer even for simple task like manual segmentation because it is not similar to what they use.

Thanks Steve. So looks like those mouse functions are fairly simply defined in that config file. Was hoping that I could simply edit this file in notepad but clearly it’s not that simple! Can’t even find such a file in my Slicer install directory.

Care to point me in the right direction?

Note that I’m not saying this is a good idea, but if you want to experiment, you can do something like this in the python console:

lm = slicer.app.layoutManager()
rw = lm.sliceWidget('Red').sliceView().renderWindow()
style = vtk.vtkInteractorStyleUser()
rw.GetInteractor().SetInteractorStyle(style)
def cb(a,b):
  print(a,b)
style.AddObserver("AnyEvent", cb)

From there you can change the callback function (cb) to do whatever you want, using the Slicer code linked above as a guide. Of course a lot of things will break if you do this :smile:

I suppose if this is becomes a common enough request we could add hooks to do things like easily filter events or remap key/mouse bindings. Of course we’re reluctant because support and documentation could be much harder if everyone starts using different buttons.

1 Like

Following this directions I’ve added custom actions just by adding a callback to a MouseWheelBackwardEvent instead of AnyEvent and not overriding the InteractorStyle.
Thanks for the snippet.

In my case I wanted to distort the Y window scale if the shift key is pressed using the field of view:

def cbBackward(interactorStyle,event):
  if interactorStyle.GetInteractor().GetShiftKey():
    fov = interactorStyle.GetSliceLogic().GetSliceNode().GetFieldOfView()
    interactorStyle.GetSliceLogic().GetSliceNode().SetFieldOfView(fov[0],fov[1]*1.2,fov[2]) 

and added the observer:

interactorStyle = slicer.app.layoutManager().sliceWidget('Red').sliceView().sliceViewInteractorStyle()    
observeridbackward = interactorStyle.AddObserver("MouseWheelBackwardEvent", cbBackward)
2 Likes