# Interactive Zoom Mouse Drag Direction

**URL:** <https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832>\
**Category:** Support\
**Created:** [May 27, 2021, 10:34pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832 "2021-05-27T22:34:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![spycolyf](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@spycolyf](https://discourse.slicer.org/u/spycolyf)\
**Post date:** [May 27, 2021, 10:34pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/1 "2021-05-27T22:34:06Z")

</div>

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?

Thanks

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [May 27, 2021, 10:52pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/2 "2021-05-27T22:52:36Z")

</div>

Reviewing the current state of your [SlicerQReads](https://github.com/KitwareMedical/SlicerQReads) custom app, it appears you are using a [modified Slicer version](https://github.com/KitwareMedical/SlicerQReads/blob/d40ce875aa49f396fc8fe2b578e477d6cd02894f/CMakeLists.txt#L15-L16) that has already swapped some zoom/pan functionality for mouse clicks by way of [this commit](https://github.com/KitwareMedical/Slicer/commit/9acdfe886eac90326c3a7075d2ae91c846eecccd). 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.

---

<div class="post-metadata">

**Author:** ![spycolyf](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@spycolyf](https://discourse.slicer.org/u/spycolyf)\
**Post date:** [June 10, 2021, 7:50pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/4 "2021-06-10T19:50:43Z")

</div>

Hi @jamesobutler,

Here’s how I attempted to reverse the zoom mouse drag direction…

1. Changed the following code in vtkMRMLSliceIntersectionWidget.cxx (MouseWheelForward = Zoom In / MouseWheelBackward = Zoom out) …

```auto
    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

```
    { "WidgetEventZoomInSlice", vtkMRMLSliceIntersectionWidget::WidgetEventZoomOutSlice },
    { "WidgetEventZoomOutSlice", vtkMRMLSliceIntersectionWidget::WidgetEventZoomInSlice },

```

1. Does this look correct?
2. Will this require a full rebuild?

Thanks

---

<div class="post-metadata">

**Author:** ![spycolyf](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@spycolyf](https://discourse.slicer.org/u/spycolyf)\
**Post date:** [June 21, 2021, 5:29pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/5 "2021-06-21T17:29:33Z")

</div>

@jamesobutler,

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/c/dc93bffd574e944fde21215fe735608ccd9e2d4b.png)

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 WidgetEventZoom **In** Slice (Zoom In) signal calls the opposite (Zoom Out) function, vtkMRMLSliceIntersectionWidget::WidgetEventZoom **Out** Slice, and visa versa.

This is obviously the wrong way to do it, right?

😑

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 21, 2021, 9:34pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/6 "2021-06-21T21:34:18Z")

</div>

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](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#customize-keyboard-mouse-gestures-in-viewers).

---

<div class="post-metadata">

**Author:** ![spycolyf](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@spycolyf](https://discourse.slicer.org/u/spycolyf)\
**Post date:** [June 22, 2021, 1:35am UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/7 "2021-06-22T01:35:10Z")

</div>

@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.

I’ll search for it. Thanks

---

<div class="post-metadata">

**Author:** ![spycolyf](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@spycolyf](https://discourse.slicer.org/u/spycolyf)\
**Post date:** [June 23, 2021, 3:48pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/8 "2021-06-23T15:48:09Z")

</div>

> [@lassoan](#):
>
> 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](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#customize-keyboard-mouse-gestures-in-viewers).

@lassoan @jamesobutler @jcfr

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](https://github.com/KitwareMedical/Slicer/commit/9acdfe886eac90326c3a7075d2ae91c846eecccd)

Also, @jamesobutler commented [here](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/2).

So why did my code [here](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/5) not work? Shouldn’t the mouse wheel at least be working in the opposite direction. Maybe I’m building incorrectly.

Should I continue to try to implement this in Python?

Thanks

---

<div class="post-metadata">

**Author:** ![spycolyf](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@spycolyf](https://discourse.slicer.org/u/spycolyf)\
**Post date:** [June 28, 2021, 2:32pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/9 "2021-06-28T14:32:05Z")

</div>

Good morning @jamesobutler @lassoan @pieper @jcfr,

Could someone please tell me why making these changes (swapping slots) would have no effect on mouse actions Zoom events after rebuilding?

 ![](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/c/dc93bffd574e944fde21215fe735608ccd9e2d4b.png)  
I’m totally lost…

Thanks

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 28, 2021, 2:55pm UTC](https://discourse.slicer.org/t/interactive-zoom-mouse-drag-direction/17832/10 "2021-06-28T14:55:18Z")

</div>

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.
