# vtkmodules.qt.QVTKRenderWindowInteractor problems

**URL:** https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521
**Category:** Support
**Created:** [October 29, 2020, 2:22pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521 "2020-10-29T14:22:39Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![crux](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/a6a055/32.png) [@crux](https://discourse.vtk.org/u/crux)
#### Post date: [October 29, 2020, 2:22pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/1 "2020-10-29T14:22:39Z")

</div>

Hello,

I have problems using the QVTKRenderWindowInteractor within Python.

At first the setup:  
OS: Windows10  
Python: 3.7.9  
PyQt: 5.15.1  
VTK: 9.0.1 (I built it with ‘python -m pip install vtk’)

I had problems with the QVTKRenderWindowInteractor from package ‘from vtkmodules.qt.QVTKRenderWindowInteractor’.  
I got the error message:  
‘vtkInteractorStyleSwitc:37 WARN| vtkInteractorStyleSwitchBase (00000233904378E0): Warning: Link to vtkInteractionStyle for default style selection.’

After reviewing the QVTKRenderWidgetConeExample I saw that  
‘import vtkmodules.vtkRenderingOpenGL2  
import vtkmodules.vtkInteractionStyle’  
prevents this error message. (Why?)

As next step i wanted to add an vtkmodules.vtkRenderingCore.vtkTextActor:  
textActor = vtkTextActor()  
textActor.SetInput(“Test”)  
ren.AddActor(textActor)  
But now I got the next error message:  
‘vtkTextActor.cxx:117 ERR| vtkTextActor (0000015B0D3347D0): Failed getting the TextRenderer instance!’  
How can I solve this kind of errors?

Btw. when using ‘vtk.qt.QVTKRenderWindowInteractor.QVTKRenderWindowInteractor’ instead of ‘vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor’ everything works fine.

What is the proper way to work with vtk in Python? (I’m just beginning to use it)  
In the Eclipse IDE I get import suggestions of vtkmodules instead of vtk, why I thought vtkmodules is the correct one.

Many thanks in advance for your help!  
-crux

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 29, 2020, 3:49pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/2 "2020-10-29T15:49:19Z")

</div>

VTK has some classes which are abstract factories. When loaded, some libraries (accessed in Python by importing them) register implementations of these abstract factories for use when asking for an instance of the base abstract factory. Without any registered classes, you get the first error you encountered. The `vtkInteractionStyle` module happens to include one of these implementations for `vtkInteractorStyleSwitchBase` which is why it fixes the problem.

You have a similar issue with `vtkTextRenderer` in the second message. `vtkRenderingFreeType` contains an implementation of that class, so importing it would fix that error.

Using `vtk.qt.…` works because the `vtk` module imports _all_ of `vtkmodules` when it is loaded. Due to this behavior, to get on-demand loading, the `vtkmodules` package was created instead.

---

<div class="post-metadata">

### Author: ![crux](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/a6a055/32.png) [@crux](https://discourse.vtk.org/u/crux)
#### Post date: [October 29, 2020, 4:03pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/3 "2020-10-29T16:03:36Z")

</div>

Thank you for the fast response.

Okay this approach makes sense. But how do i know which libraries I have to import to register the abstract factories? For example for `vtkTextRenderer`?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 29, 2020, 4:21pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/4 "2020-10-29T16:21:40Z")

</div>

Unfortunately, there’s no way for the base class to know what you actually want. What I did was grep for `vtkTextRenderer` in the `CMakeLists.txt` files in VTK’s repo and saw that there was a `BASE vtkTextRenderer` in the `Rendering/FreeType` directory. Since it was the only one provided by VTK itself, this seems like the best solution.

---

<div class="post-metadata">

### Author: ![crux](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/a6a055/32.png) [@crux](https://discourse.vtk.org/u/crux)
#### Post date: [October 29, 2020, 4:33pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/5 "2020-10-29T16:33:11Z")

</div>

Okay cool, thank you very much for the advice and the solution!

When i change `import vtkmodules.vtkInteractionStyle` to `import vtkmodules.vtkInteractionWidgets` it also works :-).

---

<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: [October 29, 2020, 4:35pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/6 "2020-10-29T16:35:52Z")

</div>

VTK itself provides exactly one implementation class for each abstract factory class, so a simple work-around is to load all of the VTK modules.

This can be done by using

```
import vtk

```

instead of

```
import vtkmodules.xxx

```

Using the “vtkmodules” package to import only the modules you need is more efficient than using the “vtk” package to load all modules, but this must be weighed against the ease-of-use of “import vtk”.

The situation could be improved greatly through better error messages, but unfortunately VTK itself does not provide any mapping that states, for any particular abstract factory class, what modules the implementation classes are stored in.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 29, 2020, 5:13pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/7 "2020-10-29T17:13:03Z")

</div>

> [@dgobbi](#):
>
> VTK itself provides exactly one implementation class for each abstract factory class, so a simple work-around is to load all of the VTK modules.

There are some classes with multiple implementations possible. `vtkOpenGLRenderWindow` has X (potentially) available on any platform. There are also OpenVR implementations for lots of things.

---

<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: [October 29, 2020, 5:23pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/8 "2020-10-29T17:23:54Z")

</div>

I’m not familiar with the situation with OpenVR, but my understanding was that the implementations for vtkRenderWindow were mutually exclusive. This is implied by the structure of the CMakeLists.txt:

```auto
if (VTK_USE_X)
elseif (WIN32)
elseif (VTK_USE_COCOA)
elseif (ANDROID)
elseif (APPLE_IOS)
endif ()

```

Am I missing something?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [October 29, 2020, 6:54pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/9 "2020-10-29T18:54:28Z")

</div>

Oh, maybe they are, but there’s no reason they should be. There’s a problem in that whatever gets registered first “wins” when there are multiples available. There’s [an issue](https://gitlab.kitware.com/vtk/vtk/-/issues/17218) for that though.

---

<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: [October 29, 2020, 7:20pm UTC](https://discourse.vtk.org/t/vtkmodules-qt-qvtkrenderwindowinteractor-problems/4521/10 "2020-10-29T19:20:25Z")

</div>

> [@ben.boeckel](#):
>
> Oh, maybe they are, but there’s no reason they should be.

So I guess that we can agree that the vtkRenderWindow overrides that exist in vtkRenderingOpenGL2 must either be 1) mutually exclusive, since they are all implemented in the same module, or 2) selectable as per the issue that you linked. Since the issue you linked is not yet resolved, it seems that mutual exclusivity is, in fact, required.
