# vtkOrientationMarkerWidget won't show in pyqt5

**URL:** https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320
**Category:** Support
**Created:** [August 8, 2021, 12:56am UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320 "2021-08-08T00:56:46Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Ricardo\_M\_Picado](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ricardo_m_picado/32/3752_2.png) [@Ricardo\_M\_Picado](https://discourse.vtk.org/u/Ricardo_M_Picado)
#### Post date: [August 8, 2021, 12:56am UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/1 "2021-08-08T00:56:46Z")

</div>

Hi, I am trying to reproduce a python (3.8) VTK (9.0.3) code:

```python
    colors = vtk.vtkNamedColors()
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    axes = vtk.vtkAxesActor()
    om = vtk.vtkOrientationMarkerWidget()
    om.SetOrientationMarker(axes)
    om.SetViewport(0.0, 0.0, 0.2, 0.2)
    om.SetInteractor(iren)
    om.EnabledOn()
    om.InteractiveOff()
    ren.SetBackground(colors.GetColor3d('Wheat'))
    ren.ResetCamera()
    renWin.Render()
    iren.Initialize()
    iren.Start()

```

(this code shows coords axes in a small widget at the lower left corner.)

to an embedded PyQt5 code. Here is the pyqt code:

```python
import sys
import vtk
from PyQt5 import QtWidgets
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

class MainWindow(QtWidgets.QMainWindow):
    def __init__ (self, parent = None):
        QtWidgets.QMainWindow. __init__ (self, parent)
        self.frame = QtWidgets.QFrame()
        self.vl = QtWidgets.QVBoxLayout()
        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
        self.vl.addWidget(self.vtkWidget)
        self.renderer = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.renderer)
        self.interactor = self.vtkWidget
        colors = vtk.vtkNamedColors()
        source = vtk.vtkSphereSource()
        source.SetCenter(0, 0, 0)
        source.SetRadius(5.0)
        source.SetThetaResolution(16)
        source.SetPhiResolution(16)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        self.renderer.AddActor(actor)
        axes = vtk.vtkAxesActor()
        om = vtk.vtkOrientationMarkerWidget()
        om.SetOrientationMarker(axes)
        om.SetViewport(0.0, 0.0, 0.2, 0.2)
        om.SetInteractor(self.vtkWidget )
        om.EnabledOn()
        om.InteractiveOff()
        self.renderer.SetBackground(colors.GetColor3d('Wheat'))
        self.renderer.ResetCamera()
        self.frame.setLayout(self.vl)
        self.setCentralWidget(self.frame)
        self.show()
        self.interactor.Initialize()
        self.interactor.Start()

if __name__ == " __main__":
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    sys.exit(app.exec_())

```

The PyQt5 code does not show the lower left widget.

Does anyone know what is wrong in my pyqt5 code ?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 9, 2021, 1:51pm UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/2 "2021-08-09T13:51:22Z")

</div>

Can you, please, place your code between ````python` and ``` markdown tokens so it is easier to read?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [August 9, 2021, 1:52pm UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/3 "2021-08-09T13:52:36Z")

</div>

done

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 9, 2021, 2:55pm UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/4 "2021-08-09T14:55:35Z")

</div>

I setup my orientation widget like this (C++):

```cpp
   //----------------------adding the orientation axes-------------------------
    vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New();
    _vtkAxesWidget = vtkSmartPointer<vtkOrientationMarkerWidget>::New();
    _vtkAxesWidget->SetOutlineColor(0.9300, 0.5700, 0.1300);
    _vtkAxesWidget->SetOrientationMarker(axes);
    _vtkAxesWidget->SetInteractor(_vtkwidget->GetRenderWindow()->GetInteractor());
    _vtkAxesWidget->SetViewport(0.0, 0.0, 0.2, 0.2);
    _vtkAxesWidget->SetEnabled(1);
    _vtkAxesWidget->InteractiveOn();
    //--------------------------------------------------------------------------

```

So I guess this line:

> [@Ricardo\_M\_Picado](#):
>
> `om.SetInteractor(self.vtkWidget )`

should be:

```python
om.SetInteractor(self.vtkWidget.GetRenderWindow().GetInteractor())

```

I hope this helps.

---

<div class="post-metadata">

### Author: ![Ricardo\_M\_Picado](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ricardo_m_picado/32/3752_2.png) [@Ricardo\_M\_Picado](https://discourse.vtk.org/u/Ricardo_M_Picado)
#### Post date: [August 9, 2021, 3:15pm UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/5 "2021-08-09T15:15:07Z")

</div>

Hi Paulo, thanks for the reply.  
Sorry for source code, I didn’t know that. But, thanks for the tip.  
Regarding the interactor, I have already tried that, and it does not work.  
I thing it could be something with “vtkmodules.qt.QVTKRenderWindowInteractor”, because the code with vtk.vtkRenderWindowInteractor() works perfectly. Could it be?  
Unfortunately, I just knew VTK a few weeks ago. There is still very much to learn …  
Thanks again.  
BR, Ricardo

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 10, 2021, 11:14am UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/6 "2021-08-10T11:14:10Z")

</div>

Well, Ricardo, I’d simply copy the working code and develop from it step-by-step until it stops working. This way you should be able to diagnose the problem. That’s what I do in face of silent bugs like that.

---

<div class="post-metadata">

### Author: ![Ricardo\_M\_Picado](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ricardo_m_picado/32/3752_2.png) [@Ricardo\_M\_Picado](https://discourse.vtk.org/u/Ricardo_M_Picado)
#### Post date: [August 17, 2021, 10:20pm UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/7 "2021-08-17T22:20:36Z")

</div>

Ok. Thank You.

---

<div class="post-metadata">

### Author: ![Hana](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hana/32/8065_2.png) [@Hana](https://discourse.vtk.org/u/Hana)
#### Post date: [November 27, 2023, 4:08am UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/8 "2023-11-27T04:08:09Z")

</div>

Hi Ricardo, I’ve faced the same problem with you, when using PyQt5 and vkt to develop a coordinate axes widget. Has this problem been solved yet?

---

<div class="post-metadata">

### Author: ![Hana](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hana/32/8065_2.png) [@Hana](https://discourse.vtk.org/u/Hana)
#### Post date: [November 27, 2023, 4:37am UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/9 "2023-11-27T04:37:25Z")

</div>

I’m not sure if you still need to solve this problem, but I’ve found a solution in this post:

> [@How to use vtkRenderWindowInteractor in QVTKOpenGLNativeWidget](https://discourse.vtk.org/t/how-to-use-vtkrenderwindowinteractor-in-qvtkopenglnativewidget/2499/3):
>
> According to your code, I define the oject ‘vtkOrientationMarkerWidget’ as a member variable of the class MyViewer instead of local variable in the function. It works! That’s the reason why I can not see the result. Thank you very much!

It seems that we both made a same mistake not to define the object ‘vtkOrientationMarkerWidget’ as a member of class ‘MainWindow’. Now my PyQt5 program can work normally.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/1/101651bc61a85d8445a93dbb84b68b4ab789cd79.png)  
And here is my code:

```python
class MainWindow(QtWidgets.QMainWindow):
    def __init__ (self, parent = None):
        super(). __init__ ()
        # create QVTKRenderWindowInteractor
        self.vtk_widget = QVTKRenderWindowInteractor(self)

        # create render and interactor
        self.renderer = vtk.vtkRenderer()
        self.vtk_widget.GetRenderWindow().AddRenderer(self.renderer)
        self.interactor = self.vtk_widget.GetRenderWindow().GetInteractor()

        # create an axes actor, remember to define it as a member variable
        self.axes_actor = vtkAxesActor()
        self.axes_actor.AxisLabelsOn()
        self.axes_actor.SetTotalLength(1.0, 1.0, 1.0)
        self.axes_actor.SetShaftTypeToCylinder()

        # create a vtkOrientationMarkerWidget, and connect it with axes actor. remember to define it as a member variable
        self.axes_widget = vtk.vtkOrientationMarkerWidget()
        self.axes_widget.SetOrientationMarker(self.axes_actor)
        self.axes_widget.SetInteractor(self.interactor)
        self.axes_widget.SetViewport(0.0, 0.0, 0.2, 0.2) 
        self.axes_widget.SetEnabled(True)
        self.axes_widget.InteractiveOn()

        # background color
        self.renderer.SetBackground(0.8, 0.8, 0.8)

        # model
        self.sphere = vtk.vtkSphereSource()
        self.sphere_mapper = vtk.vtkPolyDataMapper()
        self.sphere_mapper.SetInputConnection(self.sphere.GetOutputPort())
        self.sphere_actor = vtk.vtkActor()
        self.sphere_actor.SetMapper(self.sphere_mapper)
        self.renderer.AddActor(self.sphere_actor)

        # camera
        self.camera = self.renderer.GetActiveCamera()
        self.camera.SetPosition(0, 0, 30)
        self.renderer.SetActiveCamera(self.camera)

        self.setCentralWidget(self.vtk_widget)

```

---

<div class="post-metadata">

### Author: ![Ricardo\_M\_Picado](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ricardo_m_picado/32/3752_2.png) [@Ricardo\_M\_Picado](https://discourse.vtk.org/u/Ricardo_M_Picado)
#### Post date: [November 28, 2023, 4:58pm UTC](https://discourse.vtk.org/t/vtkorientationmarkerwidget-wont-show-in-pyqt5/6320/10 "2023-11-28T16:58:22Z")

</div>

Thank you.
