How to access QVTK... classes in Python

Hi everyone !

I need to use a VTK function called QVTKOpenGLStereoWidget in Python.
I saw a vtk example where they did this way :

from PyQt4 import QtGui
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

And then use it like this :

class MainWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)

        self.frame = QtGui.QFrame()
        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)

However, after looking at some topics, it seems Slicer uses PythonQt and not PyQt.
So in order to access my class, can I just remplace PyQt4 to PythonQt and qt4 with qt5, or do I need to do differently ?

Thanks for the help !


Normally you can access any VTK class in the main vtk module. Like vtk.vtkCollection(). However, this particular module seems not to be Python wrapped. I’d use the vtkQWidgetWidget class from the same module but also could not figure out how, so I added a C++ function using it directly that I then call form Python.

OK thanks for the infos I’ll do that ! :slight_smile: