Trouble using VTK Widget with QVTK

Hi, guys,

So, I’m have a trouble to use QVTKRenderWindowInteractor and vtkContourWidget
I have this program


This is how I made it:

class SimulationWindow(QMainWindow):
def init(self):
super().init()
self.initWindow()

    #VTKInteractor
    self.frame = QFrame()
    self.vl = QVBoxLayout()
    self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
    self.vl.addWidget(self.vtkWidget)

    ##Vtk
    self.renderer = vtk.vtkRenderer()
    self.vtkWidget.GetRenderWindow().AddRenderer(self.renderer)
   
   #Actors 
    self.xraysource = buildDiskActor(position=(100, 130))
    self.renderer.AddActor(self.xraysource)
    self.objects_dic['source'] = self.xraysource

    self.object = buildDiskActor(position=(350, 300), color=(0.9, 0.9, 0.9))
    self.renderer.AddActor(self.object)
    self.objects_dic['object'] = self.object

    self.detector = buildCubeActor(position=(500, 400))
    self.renderer.AddActor(self.detector)
    self.objects_dic['detector'] = self.detector
    self.renderer.ResetCamera()
    self.frame.setLayout(self.vl)
    self.setCentralWidget(self.frame)

    #Interactor
    self.interactor = self.vtkWidget.GetRenderWindow().GetInteractor()
    inStyle = CustomInteractor(self.renderer, self.vtkWidget.GetRenderWindow(), self.objects_dic)
    self.interactor.SetInteractorStyle(inStyle)

    self.show()
    self.interactor.Initialize()

obs. My CustomInteractor extends vtkInteractorStyleTrackballActor

Well, when I Right Click on a object, I want to change my interactor to ContourWidget effects
to do this I make this function:

def buildCustomTrajectory(self):

    render_window = vtk.vtkRenderWindow()
    render_window.AddRenderer(self.renderer)

    render_interactor = vtk.vtkRenderWindowInteractor()
    render_interactor.SetRenderWindow(render_window)

    contour_widget = vtk.vtkContourWidget()
    contour_widget.SetInteractor(render_interactor)
    contour_widget.CreateDefaultRepresentation()

    render_interactor.Initialize()

    contour_widget.On()
    render_window.Render()

    render_interactor.Start()
    self.renderer.ResetCamera()

But when I execute this, he open another window like that:

In the new window ContourWidget is working, but my main window does nothing, and I really want that the contourWidget working in my main window application with QVTK.

I tried many ways to Set vtkRenderWindow to my self.vtkWidget, but only open a new White Window.
I have to put the vtkRenderWindow Because contour widget only accept vtkRenderWindowInteractor, and I have to set a vtkRenderWindow to vtkRenderWindowInteractor.

Someone can help me with this? I’m really stuck here.

I found a problem like mine here http://vtk.1045678.n5.nabble.com/Trouble-using-VTK-Widget-with-QVTK-td5727389.html
but in this case he is using c++ and to solve used the class QVTKOpenGlWidget, that I think doesn’t have on python.

My regards.

Python 3.7, vtk 8.2, PyQt5.

You can try using QVTKRenderWindowInteractor.py, it is a pure-python alternative to QVTKOpenGLWidget.

Edit: Oops, it looks like you are already doing this. Sorry for the noise.

Thank you anyway, I just cant solve it with QVTKRenderWindowInteractor. Maybe I go to CTK or pyside to do this, but dont know how yet.

CTK uses PythonQt for wrapping. PythonQt embeds Python in a C++ application, so you get more control, potentially higher performance, cleaner packaging, etc. but you need to compile your executable (such as the ctkSimplePythonShell example application).