Using vtkImageTracingWidget with QT in python crash

Hi everyone,

I have a problem with the implementation of Vtk ImageTracerWidget using Qt and python.
I have found an example that works using a vtkRenderWindowInteractor

(https://github.com/Kitware/VTK/blob/master/Examples/GUI/Python/ImageTracerWidget.py)

Using the next code I’m able to display an image and trace over the image without problem using the next code:

    imageActor = vtk.vtkImageActor()
    imageActor.GetMapper().SetInputConnection(bmpReader.GetOutputPort())
    imageActor.VisibilityOn()
    imageActor.InterpolateOff()

    ren = vtk.vtkRenderer()
    ren.SetBackground(0.4, 0.4, 0.5)    
   
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    interactor = vtk.vtkInteractorStyleImage()
   
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(interactor)
    iren.SetRenderWindow(renWin)

    itw = vtk.vtkImageTracerWidget()
    itw.SetCaptureRadius(100)
    itw.GetGlyphSource().SetColor(1, 0, 0)
    itw.GetGlyphSource().SetScale(3.0)
   
    itw.GetGlyphSource().SetRotationAngle(45.0)
    itw.GetGlyphSource().Modified()
    itw.ProjectToPlaneOn()
    itw.SetViewProp(imageActor)
    itw.SetInputData(imageActor.GetInput())
    itw.SetInteractor(iren)
    itw.PlaceWidget()
   
    itw.SnapToImageOff()
    itw.AutoCloseOn()
   
    itw.On()
   
    ren.AddViewProp(imageActor)
    renWin.Render()
   
    vtk.vtkMapper.SetResolveCoincidentTopologyToPolygonOffset()
    vtk.vtkMapper.SetResolveCoincidentTopologyPolygonOffsetParameters(10,10)
                  
    iren.Initialize()
    renWin.Render()
    iren.Start()

This code displays the image in a new vtkRenderWindow and let me work with the tracer without problems, however when I try to use a QVTKRendererWindowInteractor to display the image in a QT UI along with the vtkImageTracerWidget it crashes after I click the image in my QT interface. The code is the next:

viewer = vtk.vtkImageViewer2()
sl = QtWidgets.QVBoxLayout(self.centralwidget)
vtkWidget = QVTKRenderWindowInteractor()

viewer.SetInputData(bmpReader.GetOutput())
viewer.Render()
viewer.GetRenderWindow().Render()
        
style = vtk.vtkInteractorStyleImage()
vtkWidget.SetInteractorStyle(style)
        
renwin = vtkWidget.GetRenderWindow()
viewer.SetRenderWindow(renwin)
viewer.GetRenderer().ResetCamera()
        
imageActor = viewer.GetImageActor() 

itw = vtk.vtkImageTracerWidget()
itw.SetCaptureRadius(100)
itw.GetGlyphSource().SetColor(1, 0, 0)
itw.GetGlyphSource().SetScale(3.0)
        
itw.GetGlyphSource().SetRotationAngle(45.0)
itw.GetGlyphSource().Modified()
itw.ProjectToPlaneOn()
itw.SetProjectionNormalToXAxes()
itw.SetProjectionPosition(pos)
itw.SetViewProp(imageActor)
itw.SetInputData(imageActor.GetInput())
itw.SetInteractor(vtkWidget)
itw.PlaceWidget()
        
itw.SnapToImageOff()
itw.AutoCloseOn()
itw.On()

sl.addWidget(vtkWidget)
vtkWidget.Initialize()
vtkWidget.Start()
frame.setLayout(self.sl)

I hope someone could help us fixing this problem. Thanks