Python Qt6 QML VTKRenderItem

Hi :-),
I want to use VTK with Pyside6 and QML. For C++ i found an example and with

QObject* topLevel = engine.rootObjects().value(0);
    QQuickWindow* window = qobject_cast<QQuickWindow*>(topLevel);
    window->show();

    QQuickVTKRenderItem* qquickvtkItem = topLevel->findChild<QQuickVTKRenderItem*>("ConeView");
    vtkRenderWindow *renderWindow = qquickvtkItem->renderWindow()->renderWindow();
    vtkRenderWindowInteractor *iRen = renderWindow->GetInteractor();
    vtkRenderer *renderer = qquickvtkItem->renderer();

on C++ side and

import QtQuick.Window
import VTK 9.3

Window {
    width: 600
    height: 600
    VTKRenderWindow {
        id: vtkwindow
        anchors.fill: parent
        VTKRenderItem {
         id: renderItem
         objectName: "ConeView"
         anchors.fill: vtkwindow
         renderWindow: vtkwindow
        }
    }
}

on QML Side, i get everything to use vtk.

But in Pyhon the VTKRenderWindow is just a QQuickItem and the Type QQuickVTKRenderItem does not exist.

So, how to use VTK in pyside6/qml apps ?

Thanks for help :slight_smile:

here is the link to the example : classQQuickVTKRenderItem. Sadly, The code does not work in Python :frowning:

Qt Quick allows you to create web-like UI on desktop. However, since VTK can now run in the web browser and you can run your C++ code (using webassembly) and Python code (for example using pyodide) natively in the web browser, too, you might consider cutting out Qt and use a web GUI framework instead (such as React or Angular).

Using Javascript framework instead of Qt for the GUI widgets may be very significant effort and most C++/Python on the web technologies are not mature yet, but the Qt company does not behave nicely (they make life of free Qt users increasingly more difficult; and licensing terms and costs for commercial Qt are unreasonable) and more and more users demand running their software natively in the browser. Therefore, web GUI should be seriously considered, especially for new projects and that can afford to use an evolving technology stack in the next few years.

have an idea—why don’t we try creating a launcher? We could first use C++ to create a Qt application and register QQuickVTKRenderItem with Qt in advance. With this, the launcher would be completed, and then we could expose this launcher to Python-Embedding, allowing the launcher to execute commands from Python. Wouldn’t this also allow PyQt or PySide6 to run a QtQuick interface while achieving compatibility with VTK? My C++ coding skills are very limited, but I think this could be feasible. Perhaps this GitHub project might offer more inspiration: GitHub - skywind3000/PyStand: 🚀 Python Standalone Deploy Environment !!.

3D Slicer, MeVisLab, maybe even MITK all use PythonQt to embed Python in a VTK/Qt application. Everything works very nicely. The drawback of PythonQt that the application is C++ first, and Python is embedded. Some Python developers don’t like this. Also, PythonQt is not as popular as PyQt and PySide.