How to use vtkRenderWindowInteractor in QVTKOpenGLNativeWidget

I want to use vtkOrientationMarkerWidget(named “widget”) in my viewer widget which is derived from QVTKOpenGLNativeWidget. I try to call widget->SetCurrentRenderer(m_render). But widget can not display in my viewer. And alse, I try to call om->SetInteractor(GetInteractor()). But it’s failed. I can control the scene of my viewer with mouse and keyboard. That’s my part of the source code. Thanks in advance.

void MyViewer::init()
    vtkSmartPointer<vtkRenderer> m_render = vtkSmartPointer<vtkRenderer>::New();


    vtkSmartPointer<vtkPropAssembly> axes = makeCubeActor(scale, xyzLabels, colors);
    vtkSmartPointer<vtkOrientationMarkerWidget> om = vtkSmartPointer<vtkOrientationMarkerWidget>::New();

    om->SetViewport(0.0, 0.8, 0.2, 1.0);

The Qt Creator output:
vtkOrientationMarkerWidget (0x1262f00): An orientation marker must be set prior to enabling/disabling widget

Hi, friend,

I think the catch is in your SetInteractor() call. In my project I do this:

//----------------------adding the orientation axes-------------------------
_vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New();
_vtkAxesWidget = vtkSmartPointer<vtkOrientationMarkerWidget>::New();
_vtkAxesWidget->SetOutlineColor(0.9300, 0.5700, 0.1300);
_vtkAxesWidget->SetViewport(0.0, 0.0, 0.2, 0.2);

The complete code is here.

1 Like

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!

1 Like

Yes… I took some time to realize that the smart pointer was being deallocated along with its scope and taking the object with it. The solution was to make it a member variable so it lives as long as the application is running.

good luck out there,


1 Like