# Block rotation in QVTKRenderWindowInteractor

**URL:** https://discourse.vtk.org/t/block-rotation-in-qvtkrenderwindowinteractor/15877
**Category:** Development
**Tags:** python
**Created:** [July 29, 2025, 1:43pm UTC](https://discourse.vtk.org/t/block-rotation-in-qvtkrenderwindowinteractor/15877 "2025-07-29T13:43:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![sapvi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sapvi/32/9874_2.png) [@sapvi](https://discourse.vtk.org/u/sapvi)
#### Post date: [July 29, 2025, 1:43pm UTC](https://discourse.vtk.org/t/block-rotation-in-qvtkrenderwindowinteractor/15877/1 "2025-07-29T13:43:18Z")

</div>

Hi all.

I am trying to find a way to use `QVTKRenderWindowInteractor` but with the blocked rotation feature. I tried to subclass it in Python and overwrite the left/right click methods but it does not seem to work in any way.

Is there any way to block the rotation possibility in `QVTKRenderWindowInteractor` (the idea is to block it temporary for some features of the app) without building some custom VTK? Purely from Python?

Thanks!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 30, 2025, 5:34pm UTC](https://discourse.vtk.org/t/block-rotation-in-qvtkrenderwindowinteractor/15877/2 "2025-07-30T17:34:04Z")

</div>

The QVTKRenderWindowInteractor passes mouse and keyboard events to the vtkRenderWindowInteractor, so customization is done via vtkRenderWindowInteractor or vtkInteractorStyle.

It’s been a long time since I’ve done this, and I don’t have any examples, but a rough outline is as follows:

```python
def onLeftButtonDown(obj, event): # or onLeftButtonDown(self, obj, event)
    print(event)

def onLeftButtonUp(obj, event):
    print(event)

interactor.AddObserver("LeftButtonPressEvent", onLeftButtonDown) # or self.onLeftButtonDown
interactor.AddObserver("LeftButtonReleaseEvent", onLeftButtonUp)

```

---

<div class="post-metadata">

### Author: ![sapvi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sapvi/32/9874_2.png) [@sapvi](https://discourse.vtk.org/u/sapvi)
#### Post date: [July 30, 2025, 11:24pm UTC](https://discourse.vtk.org/t/block-rotation-in-qvtkrenderwindowinteractor/15877/3 "2025-07-30T23:24:12Z")

</div>

> [@dgobbi](#):
>
> ```auto
> interactor.AddObserver("LeftButtonPressEvent", onLeftButtonDown) # or self.onLeftButtonDown
> interactor.AddObserver("LeftButtonReleaseEvent", onLeftButtonUp)
> 
> ```

Hi! Thanks. Thing is, when I do `AddObserver`, the related callback is indeed called **but** the original interaction is still possible. I.e. everything in the `onLeftButtonDown` callback is executed, but the original rotation is still available 😕 Any idea how to actually overwrite default behavior, not just add new observer on top of it?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 30, 2025, 11:33pm UTC](https://discourse.vtk.org/t/block-rotation-in-qvtkrenderwindowinteractor/15877/4 "2025-07-30T23:33:26Z")

</div>

The observers might have to be added to the InteractorStyle rather than the Interactor. I haven’t experimented with it for a long time.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 31, 2025, 2:15am UTC](https://discourse.vtk.org/t/block-rotation-in-qvtkrenderwindowinteractor/15877/5 "2025-07-31T02:15:24Z")

</div>

I think that I found the secret sauce, and there are two ingredients:  
a) the observers need to be added to the InteractorStyle  
b) the InteractorStyle must not be vtkInteractorStyleSwitch

For example:

```python
# The trackball camera style is the most popular style
style = vtkInteractorStyleTrackballCamera()
interactor.SetInteractorStyle(style)
style.AddObserver("LeftButtonPressEvent", onLeftButtonDown)
style.AddObserver("LeftButtonReleaseEvent", onLeftButtonUp)

```

The problems with vtkInteractorStyleSwitch are  
a) it’s the default style, it’s what you get if you don’t set a different style  
b) adding observers to vtkInteractorStyleSwitch doesn’t work

The reason observers don’t work with vtkInteractorStyleSwitch is because it actually contains several internal vtkInteractorStyle objects, and it chooses which one to connect to the interactor. It’s not possible to get access to these internal styles to add observers to them. Since vtkInteractorStyleSwitch itself is just a container, adding observers to it has no effect.

---

<div class="post-metadata">

### Author: ![sapvi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sapvi/32/9874_2.png) [@sapvi](https://discourse.vtk.org/u/sapvi)
#### Post date: [July 31, 2025, 10:28am UTC](https://discourse.vtk.org/t/block-rotation-in-qvtkrenderwindowinteractor/15877/6 "2025-07-31T10:28:01Z")

</div>

Oh wow, did not think about it, and this is indeed correct! Thank you.
