QVTKOpenGLNativeWidget requires a `vtkGenericOpenGLRenderWindow`. ` vtkWin32OpenGLRenderWindow ` is not supported.

Hi,

I am using Qt 5.15.0 framework and my VTK version is 9.0.
I am new to VTK and I am working on reading the DICOM image application in Qt framework using VTK. The application is showing the DICOM image in a separate window, but I want the DICOM image to be executed in the MainWindow.

I have attached a screenshot of the error and also I got the following error.

QVTKOpenGLNativeWidget requires a vtkGenericOpenGLRenderWindow. vtkWin32OpenGLRenderWindow is not supported.

How to deal with this?

Thanks in advance.

Use a vtkGenericOpenGLRenderWindow instead of a vtkWin32OpenGLRenderWindow.

But, I checked my code, I have replaced vtkWin32OpenGLRenderWindow with vtkGenericOpenGLRenderWindow and it still shows the same error.

Is there any other place i have to look anywhere like in VTK sources files?

Nope, it must be in your code.

Just put a breakpoint in the vtkWin32OpenGLRenderWindow constructor.

I tried and it’s still the same. I also created a new project and I built , still the error is same.
Is there any alternate solution or any other library ?

Thanks in advance.

Maybe post you code will be better.

I have encountered the same problem. I had an old code using obsolete QVTKWidget that could not compile with VTK 9 until I replaced QVTKWidget with QVTKOpenGLNativeWidget. The runtime error was caused by passing an instance of vtkRenderWindow as a parameter of SetRenderWindow method. I guess that years ago QVTWidget did not create RenderWindow automatically and that was the solution. Unfortunately, vtkRenderWindow is in fact vtkWin32OpenGLRenderWindow, which is not supported in QVTKOpenGLNativeWidget. My solution: simply remove the line with SetRenderWindow.

@besoft @giri_lakshman maybe you want to follow the example in this link: https://kitware.github.io/vtk-examples/site/Cxx/Qt/SideBySideRenderWindowsQt/ it works for me.

@mwestphal I have another issue when switching from vtk8 to vtk9. The rendering time is roughly 5 times slower than vtk8. I think it’s because of using the vtkGenericOpenGLRenderWindow instead of vtkWin32OpenGLRenderWindow. What a pity that I cannot use vtkWin32OpenGLRenderWindow anymore. Also vtkWin32OpenGLRenderWindow has some advantage of reusing the opengl shared context. My biggest problem now is the poor rendering time. Is there anything else affecting the performance between vtk8 and vtk9?

This is unlikely.

my application has a lot of QVTKOpenGLNativeWidget/vtkGenericOpenGLRenderWindow let’s say 18 instances. when I reduce the number of QVTKOpenGLNativeWidget to 4 it is getting better but way more slower than the version using vtk8. What’s your opinion?

What’s your opinion?

VTK is used by a number of applications, including ParaView. A 5x rendering time increase would definitely have been noticed.

That being said, it is possible that your application experience slowness after making some changes, but it can’t be generalized.

BTW you can try opening 18 windows in ParaView and see if you have the same problem.

I have tested vtk9 with QVTKWidget (recovered from the commit: “Removing QVTKWidget and all related classes”
f55f45faced3ddd37d30ef811558b009ae6d6746) and it’s as fast as the vtk8, please see the following link:

However, with if I use QVTKOpenGLNativeWidget, it will be very laggy as shown in the video link below:

I suspect it has something to do with the new QOpenGLWidget concept. It would be nice if you could confirm and maybe have some idea to improve the rendering performance of QVTKOpenGLNativeWidget. Otherwise I have to use the QVTKWidget in my own forked branch. Which is hard to maintain and not optimal. Many thanks.

You can try the QVTKOpenGLStereoWidget if you want.

it renders as fast as expected. Thank you very much!

@mwestphal the QVTKOpenGLStereoWidget has the limitations of “Stacking order; The embedded window will stack on top of the widget hierarchy as an opaque box”. I need to render some widgets on top of it so my only option is to come back to the deprecated QVTKWidget

the deprecated QVTKWidget

Which is deprecated because Qt deprecated the mechanism on top of which it was based, just sayin.

now when using the QVTKWidget, I cannot get the correct depth data from the function vtkOpenGLRenderWindow::GetZbufferData. What do I need to change to make it work again?

I found a work around to this issue by not using any of QVTKOpenGLNativeWidget/QVTKOpenGLStereoWidget/QVTKWidget. Instead, I just pass the QWidget.windId to the vtkWin32OpenGLRenderWindow as follows:

QFrame* viewFrame = new QFrame;
mainLayout->addWidget(viewFrame, 0, 0, 2, 2);
vtkNew<vtkWin32OpenGLRenderWindow> renderWindow;
renderWindow->SetParentId((HWND)viewFrame->winId());

The important point here is that I use SetParentId and have to handle mouse events myself and depth picking works well.