Currently, when you interactively zoom with the mouse, dragging the mouse up zooms out, and dragging down zooms in. I’m using my slicer module as an extension to a main app that zooms in the opposite direction. This confuses the users making them zoom in the wrong direction when in the slicer module UI.
Is there a way to make mouse drag up zoom in and mouse drag down zoom out?
Reviewing the current state of your SlicerQReads custom app, it appears you are using a modified Slicer version that has already swapped some zoom/pan functionality for mouse clicks by way of this commit. For inverting zoom in/out based on those mouse interactions I would suggest to look in those same files as that commit to then invert some more logic.
Here’s how I attempted to reverse the zoom mouse drag direction…
Changed the following code in vtkMRMLSliceIntersectionWidget.cxx (MouseWheelForward = Zoom In / MouseWheelBackward = Zoom out) …
this->SetEventTranslation(WidgetStateIdle, vtkCommand::MouseWheelForwardEvent, vtkEvent::ControlModifier, WidgetEventZoomInSlice); // DVP swapped Zoom In and Zoom Out
this->SetEventTranslation(WidgetStateIdle, vtkCommand::MouseWheelBackwardEvent, vtkEvent::ControlModifier, WidgetEventZoomOutSlice); // DVP swapped Zoom In and Zoom Out
… And these lines in the PyObject *PyvtkMRMLSliceIntersectionWidget_ClassNew() method in vtkMRMLSliceIntersectionWidgetPython.cxx
I made the above changes. I simply swapped the zoom in/out Signals slots so that in calls out and out calls in. For instance…
The WidgetEventZoomInSlice (Zoom In) signal calls the opposite (Zoom Out) function, vtkMRMLSliceIntersectionWidget::WidgetEventZoomOutSlice, and visa versa.
Changing the mapping like this is fine, but it would be a bit more future-proof if you did not change the Slicer core source code but instead you would run some Python code at startup to change the mapping. See example here.
@lassoan, I disagree that it’s fine. I’d like your way much better if I can now figure out the correct parameters to use for the Zoom mouse drag and mouse wheel direction.
Hello @lassoan, I stayed up till past 2 in the morning trying to figure out the secret formula for changing the zoom in/out mouse drag direction using Python. Then I began to wonder why @jcfr did not use Python here
It should not be necessary to look into the generated Python wrapper. It is the exact translation of the corresponding header file to a Python object. It contains no additional information compared to the header file.
Changing the translation from GUI event to widget event in the constructor should work well. Changing it in Python is more flexible, but you need to do it for each view (and if you switch layout then you need to do it for the newly created view, too). Also make sure to remove the old mapping before trying to add a new one.