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();
    GetRenderWindow()->AddRenderer(m_render);

    ......

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

    om->SetViewport(0.0, 0.8, 0.2, 1.0);
    om->EnabledOn();
    om->SetOrientationMarker(axes);
    om->SetInteractor(GetInteractor());
    om->InteractiveOn();
    om->SetCurrentRenderer(m_render);
}

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->SetOrientationMarker(axes);
_vtkAxesWidget->SetInteractor(_vtkwidget->GetRenderWindow()->GetInteractor());
_vtkAxesWidget->SetViewport(0.0, 0.0, 0.2, 0.2);
_vtkAxesWidget->SetEnabled(1);
_vtkAxesWidget->InteractiveOn();
//--------------------------------------------------------------------------

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!

2 Likes

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,

Paulo

2 Likes

Thanks a lot! I’ve been debugging in PyQt version for a long time without success until I find your post.