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

**URL:** <https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650>\
**Category:** Development\
**Created:** [October 20, 2022, 2:00am UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650 "2022-10-20T02:00:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![edwardAllen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/edwardallen/32/4576_2.png) [@edwardAllen](https://discourse.vtk.org/u/edwardAllen)\
**Post date:** [October 20, 2022, 2:00am UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650/1 "2022-10-20T02:00:07Z")

</div>

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

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

bug1.qml

```auto
 ...
    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

```auto
 ...
    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......
```

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)\
**Post date:** [October 20, 2022, 11:41am UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650/2 "2022-10-20T11:41:16Z")

</div>

Cc: @sankhesh

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

---

<div class="post-metadata">

**Author:** ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)\
**Post date:** [October 20, 2022, 12:35pm UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650/3 "2022-10-20T12:35:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edwardAllen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/edwardallen/32/4576_2.png) [@edwardAllen](https://discourse.vtk.org/u/edwardAllen)\
**Post date:** [October 20, 2022, 1:20pm UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650/4 "2022-10-20T13:20:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_Jackson](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael_jackson/32/61_2.png) [@Michael\_Jackson](https://discourse.vtk.org/u/Michael_Jackson)\
**Post date:** [October 20, 2022, 1:58pm UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650/5 "2022-10-20T13:58:43Z")

</div>

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

[QQuickVtkItem.cxx](https://discourse.vtk.org/uploads/short-url/6iqXMhTvuUECkdti8of9powsPg2.cxx) (16.3 KB)

[QQuickVtkItem.h](https://discourse.vtk.org/uploads/short-url/5FSRFBtzm4hW8USvN31Cl9MGowf.h) (3.26 KB)

---

<div class="post-metadata">

**Author:** ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)\
**Post date:** [October 20, 2022, 2:12pm UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650/6 "2022-10-20T14:12:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edwardAllen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/edwardallen/32/4576_2.png) [@edwardAllen](https://discourse.vtk.org/u/edwardAllen)\
**Post date:** [October 21, 2022, 1:08am UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650/7 "2022-10-21T01:08:57Z")

</div>

Thanks for sharing , I will test it today . 👍 👍 👍

---

<div class="post-metadata">

**Author:** ![John.Stone](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/a6a055/32.png) [@John.Stone](https://discourse.vtk.org/u/John.Stone)\
**Post date:** [December 16, 2022, 5:02pm UTC](https://discourse.vtk.org/t/some-bugs-when-use-vtk-in-qml-use-the-official-way/9650/8 "2022-12-16T17:02:01Z")

</div>

Pull Request with fix  
[https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/9763](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9763)
