Vtk9.x Cannot used in QQuickFramebufferObject::Renderer *createRenderer() but vtk8.x can do .

See below project :

nicanor-romero/QtVtk: An integration between Qt Quick Controls 2 and VTK for 3D rendering (github.com)


qCring/QuickVtk: A VTK prototyping application based on QtQuick/QML (github.com)

They are use qt createRenderer() and createFramebufferObject() to create Vtk in qml. And this method is avaliable in Vtk 8.2 , but can not use in version after vtk 9.1.

No errors , but this have no picture .

After use official method of using vtk with qml suck like qquickVtkRenderWindow and other method such like qt::createRenderer() , I think use qt::createRenderer() is the best way to use vtk in qml . but after 9.x , this method can not used anymore ,

Cc: @sankhesh

If you need some source code I changed for building , I will upload them.

@edwardAllen, It might be related to differences in how the OpenGL context is set up in Qt and VTK.
Hard to say without actually looking into it. Since you had it working at some point, you could use git bisect to figure out the change that broke it.

I had see the different between vtk 9.2 and vtk 8.2 , and I had changed some thing to make program running , but it show nothing , and I cannot figure out where the bug is . Here are a demo by using this method , hope you can see it .
testViewerWithFrameBuffer.zip (37.6 KB)

I had checkout many method to use vtk with qml , but after update vtk to 9.x , official give a qquickVtkRenderWindow dem it have many bugs when use it with qml , and if I back to use method
useful in vtk 8.2 , that method qt::createRenderer() not working with 9.x , so , until 9.2 , here are still not have a suitable method, I think qt::createRenderer() maybe a good method. , but I cannot fix the issue show nothing…


We did some work on a project in mid 2021 that had tried to fix a lot of these issues. Not sure if we ever put in a PR for it or not. Those commits have some of that work. We got a lot of VTK working nicely with QML. Ultimately we ended up dumping QML for other reasons and went back to widgets.

I think we were mainly editing the example code to get VTK working with QML. You can take a look at that code and see if any of it is still relevant.

Did you manage to find a solution? I just migrated a qml/VTK viewer based on QQuickFramebufferObject from VTK 8.2 to VTK 9.2.5 and I’m in the dark ie I have black screen because nothing is rendered.

I attempted many tweaks but no success yet…

Thanks for your help.

Please use the QQuickVTKItem for integrating VTK in a QML application.

I managed to make it work again after migration (without using QQuickVtkItem). Here are my changes if anyone is interested:

diff --git a/src/app/view/modules/QmlVTK/QVTKFramebufferObjectRenderer.cpp b/src/app/view/modules/QmlVTK/QVTKFramebufferObjectRenderer.cpp
index ff40743..d4f8208 100644
--- a/src/app/view/modules/QmlVTK/QVTKFramebufferObjectRenderer.cpp
+++ b/src/app/view/modules/QmlVTK/QVTKFramebufferObjectRenderer.cpp
@@ -13,6 +13,8 @@
 #include "QVTKFramebufferObjectItem.h"
 // lib headers
+#include <vtkOpenGLState.h>
 #include <QQuickWindow>
 QVTKFramebufferObjectRenderer::QVTKFramebufferObjectRenderer() {
@@ -20,6 +22,14 @@ QVTKFramebufferObjectRenderer::QVTKFramebufferObjectRenderer() {
     m_vtkRenderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
+    m_vtkRenderWindow->AddObserver(
+        vtkCommand::WindowMakeCurrentEvent, this,
+        &QVTKFramebufferObjectRenderer::makeCurrentCallback);
+    m_vtkRenderWindow->AddObserver(
+        vtkCommand::WindowSupportsOpenGLEvent, this,
+        &QVTKFramebufferObjectRenderer::supportsOpenGLCallback);
     m_renderer = vtkSmartPointer<RendererType>::New();
@@ -30,6 +40,17 @@ QVTKFramebufferObjectRenderer::QVTKFramebufferObjectRenderer() {
+void QVTKFramebufferObjectRenderer::makeCurrentCallback(vtkObject*,
+                                                        unsigned long, void*) {
+    m_vtkRenderWindow->SetIsCurrent(true);
+void QVTKFramebufferObjectRenderer::supportsOpenGLCallback(vtkObject*,
+                                                           unsigned long,
+                                                           void*) {
+    m_vtkRenderWindow->SetSupportsOpenGL(true);
 void QVTKFramebufferObjectRenderer::synchronize(
     QQuickFramebufferObject* p_item) {
     if (!m_vtkFboItem) {
@@ -55,7 +76,6 @@ void QVTKFramebufferObjectRenderer::render() {
-    m_vtkRenderWindow->Start();
     static bool firstRender{true};
     if (firstRender) {
@@ -70,32 +90,26 @@ void QVTKFramebufferObjectRenderer::render() {
 void QVTKFramebufferObjectRenderer::openGLInitState() {
-    m_vtkRenderWindow->OpenGLInitState();
-    m_vtkRenderWindow->MakeCurrent();
-    QOpenGLFunctions::glUseProgram(0);
+    m_vtkRenderWindow->GetState()->Initialize(m_vtkRenderWindow);
+    m_vtkRenderWindow->OpenGLInitState();
+    glUseProgram(0);
+    glEnable(GL_BLEND);
 QVTKFramebufferObjectRenderer::createFramebufferObject(const QSize& p_size) {
     QOpenGLFramebufferObjectFormat format;
-    format.setAttachment(QOpenGLFramebufferObject::Depth);
+    format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
     std::unique_ptr<QOpenGLFramebufferObject> framebufferObject(
         new QOpenGLFramebufferObject(p_size, format));
-    m_vtkRenderWindow->SetBackLeftBuffer(GL_COLOR_ATTACHMENT0);
-    m_vtkRenderWindow->SetFrontLeftBuffer(GL_COLOR_ATTACHMENT0);
-    m_vtkRenderWindow->SetBackRightBuffer(GL_COLOR_ATTACHMENT0);
-    m_vtkRenderWindow->SetFrontRightBuffer(GL_COLOR_ATTACHMENT0);
-    m_vtkRenderWindow->SetOffScreenRendering(true);
-    m_vtkRenderWindow->Modified();
     return framebufferObject.release();

Hello @kenavolic
ist it possible to get the full QVTKFramebufferObjectRenderer class? with your changes? Or do you have a github repo, where one can get it?
I am trying to get the qml-vtk-python project to work in python, and it could be that i am struggle around with the same problem that you did.
I tried changing the posted includes/excludes, but i didnt get it working in cpp => All I see is just a short flickering of the qt window and then it crashes. The debugger tells me it is a Segmentation fault, because of any QEvent.