Run VTK example in Qt

Hi,

I’m beginner at VTK and I need help to start working with that.

I built VTK library. I can run examples from official site. But to run them I add the following code:

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingContextOpenGL2); // this is for 2D graphics link
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);

I found that in Internet but I don’t understand why should I add these lines?

So when I run these examples a new window appear where I can see the created objects. But how to display VTK objects in Qt window? I have QVTKWidget (see picture below, I just put QVTKWidgetPlugin.dll in ...Qt\Tools\qtcreator-4.11.0\bin\plugins\designer) but I dont know how to use it. Could you please give me some simple example of doing that?

I use Windows 10 x64, Qt 5.14, MSVC 2017 x64 compilator

Best regards,
Kerim

Hi,

I’ve found information that QVTKWidget is deprecated and for latest versions of VTK (I use VTK 8.2.0) one should use QVTKOpenGLWidget.
Is there a way of creating window where VTK object is displayed in Qt designer? For example if I want that VTK object takes only half of UI window I would like to draw this area in Qt designer.

kerim

Hello, Kerim,

To use a non-vanilla Qt class in Qt Creator you can resort to something called “promotion”. You add, for example a QWidget, then select it in the widgets tree and choose “promote to” in the context menu. A dialog will appear, prompting you to enter the name of the class and to choose the header file that defines it. More details on the promotion process can be found here. This the easy way to do it, but the drawback is that Qt Creator will not be aware of any custom properties the new class may have.

To have full access to QVTKOpenGLWidget's properties, you need to add VTK’s Qt Creator plug-in .DLL/.SO to the plugins directory in Qt Creator installation directory. Details on this you can find here.

regards,

Paulo

1 Like

Hi Paulo,

Yes, yesterday I coud run example via Widget promotion like on the see picture and I was so happy :slight_smile:
I also have QVTKWidgetPlugin.dll but I’ve found information that QVTKWidget is deprecated. Does that mean that I should use VTK Widget in Qt that we can see on widget list after adding QVTKWidgetPlugin.dll in QtCreator’s plugins?

Kerim

Yes, unfortunatelly. You need a plug-in that encapsulates a QVTKOpenGLWidget in order to use the recommended class. If the plug-in doesn’t add QVTKOpenGLWidget to your widgets list, then you’re better off just using promotion.

1 Like

Tank you!
I will keep in mind this information