Some bugs when use vtk in qml.(Use the official way )

Here are some bugs when use official demo quickVtkRenderwindow with qml.

First :
In qml file , QQuickVtkRenderer cannot in Rectangle ,like this :

bug1.qml

 ...
    VTKRenderWindow {
       id: vtkwindow
       width: 400
       height: 400
     }
 
     // add one or more vtk render items
    Rectangle{
    id : parentRect
     width : 200
    height: 200
     VTKRenderItem {
       objectName: "VolumeView"
       x: 0
       y: 0
       width: 200
       height: 200
       // Provide the handle to the render window
       renderWindow: vtkwindow
     }
     }

In my test , if parentRect has width and height , the VtnRenderItem show nothing .
And if I change Rectangle to Item , that not happen.

Second :
Can not use visible to show or hide vtk either set the visible property of windows to false or the visible property of renderItem to false dynamically . It’s just to freeze the picture, not hide the picture.
like this:

bug2.qml

 ...
    Rectangle{
    id : _button
    width : 100
    height: 100 
    MouseArea{
         anchors.fill : parent
         onClicked:{
             vtkwindow.visible = !vtkwindow.visible
             _renderer.visible = !_renderer.visible
          }
    }
             
    VTKRenderWindow {
       id: vtkwindow
       width: 400
       height: 400
     }
 
     // add one or more vtk render items
    Rectangle{
    id : parentRect
    VTKRenderItem {
      id : _renderer
       objectName: "VolumeView"
       x: 0
       y: 0
       width: 200
       height: 200
       // Provide the handle to the render window
       renderWindow: vtkwindow
     }
     }


There is another bug that is not listed for the time being......
2 Likes

Cc: @sankhesh

(making the content different for Discourse’s spam detection)

@edwardAllen These are known issues that result from the way the VTK view is rendered in the QtQuick OpenGL context.

So If I want use vtk in Qml ,the qt::createRenderer() is a better way right ? But I had post the error about use vtk with qml by using qt::createRenderer() method , so hope you can see that issue.

For what it is worth, here is some of the code that we came up with. Worked really well actually.

QQuickVtkItem.cxx (16.3 KB)

QQuickVtkItem.h (3.26 KB)

1 Like

Thanks for sharing @Michael_Jackson. Perhaps we can use some of that logic in the existing VTK items.

Thanks for sharing , I will test it today . :+1: :+1: :+1: