# Using vtkImageTracingWidget with QT in python crash

**URL:** https://discourse.vtk.org/t/using-vtkimagetracingwidget-with-qt-in-python-crash/2545
**Category:** Support
**Created:** [February 4, 2020, 8:26pm UTC](https://discourse.vtk.org/t/using-vtkimagetracingwidget-with-qt-in-python-crash/2545 "2020-02-04T20:26:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![FabianTRobles](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/df788c/32.png) [@FabianTRobles](https://discourse.vtk.org/u/FabianTRobles)
#### Post date: [February 4, 2020, 8:26pm UTC](https://discourse.vtk.org/t/using-vtkimagetracingwidget-with-qt-in-python-crash/2545/1 "2020-02-04T20:26:08Z")

</div>

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](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

---

<div class="post-metadata">

### Author: ![yangyang117](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/da6949/32.png) [@yangyang117](https://discourse.vtk.org/u/yangyang117)
#### Post date: [December 10, 2023, 3:37am UTC](https://discourse.vtk.org/t/using-vtkimagetracingwidget-with-qt-in-python-crash/2545/3 "2023-12-10T03:37:52Z")

</div>

Hello, have you resolved this issue? I also want to use QT to draw trajectories on imageviewer2, but I cannot use vtkImageTracerWidget or QT’s pen.
