I’m not sure if you still need to solve this problem, but I’ve found a solution in this post:
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.
And here is my code:
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)