vtkOrientationMarkerWidget won't show in pyqt5

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

    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:

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 ?

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

done

1 Like

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

   //----------------------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:

should be:

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

I hope this helps.

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

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.

Ok. Thank You.