# Vtk9.1 for Qml with QQuickvtkrenderItem have some issues.

**URL:** https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601
**Category:** Development
**Created:** [January 8, 2022, 6:47am UTC](https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601 "2022-01-08T06:47:18Z")
**Posts on this page:** 7
**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: [January 8, 2022, 6:47am UTC](https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601/1 "2022-01-08T06:47:18Z")

</div>

Hi every developer , hope you can see this:

I found some issues when I use vtk9.1 and qml .Below is the one description ：

- When I add a cameraorientationwidget with QQuickVTKInteractiveWidget by use `QQuickVTKRenderItem::addWidget(QQuickVTKInteractiveWidget* w) ,` and the widget not work normally , such like when the mouse hold on the actor on widget , The "X " or “Y” or “Z” do not highlight and click the actor it has no response, but it should rotate the camera .
- When I debug the application I found that the actor cannot be selected by vtkhardwareselector , because everytime mouse event will lead to a pixel buffer set and release , but It should have render event between set and release buffer , and the reason why the render() work is the renderer is not correctly in vtkRenderer::PickProp() function , but I don’t know how and why I should do , I can not find any documents for this and there are no similar issue with this.  
Here is some code

```auto
m_QQuickvtkrenderItem = topLevel->findChild<MyQQuickVTKRenderItem*>("ConeView");
...
...
 vtkSmartPointer<vtkInteractorStyleTrackballCamera2> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera2>::New();
    vtkNew<vtkRenderWindowInteractor> iRen;
    m_QQuickvtkrenderItem->renderWindow()->renderWindow()->GetInteractor()->SetInteractorStyle(style);
    style->SetDefaultRenderer(m_QQuickvtkrenderItem->renderer());
    style->setQtItem(this);
    QQuickVTKInteractiveWidget* interactorWidget = new QQuickVTKInteractiveWidget(m_QQuickvtkrenderItem->renderWindow());
    interactorWidget->setWidget(camOrientManipulator);
    interactorWidget->setEnabled(true);
    m_QQuickvtkrenderItem->addWidget(interactorWidget);
    camOrientManipulator->SetParentRenderer(m_QQuickvtkrenderItem->renderer());
    camOrientManipulator->SetInteractor(m_QQuickvtkrenderItem->renderWindow()->renderWindow()->GetInteractor());
    m_QQuickvtkrenderItem->renderWindow()->interactorAdapter()->SetEnableHover(true);
    m_QQuickvtkrenderItem->update();
    camOrientManipulator->EnabledOn();
    camOrientManipulator->On();`

```

And here is my project address , [GitHub - dezbracaty/QtVtk9.1: A qt vtk demo with vtk 9.1](https://github.com/dezbracaty/QtVtk9.1)

I hope someone can help me to resolve this issue and help more people to use vtk9.1 with qml .  
Very thanks for everyone.

 ![Screenshot_20220107_162504](https://discourse.vtk.org/uploads/default/original/2X/e/eb1b42b4439c07b7504c0b590c86820227c4c690.jpeg)

---

<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: [January 8, 2022, 6:50am UTC](https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601/2 "2022-01-08T06:50:44Z")

</div>

This is Application running interface ：

 ![Screenshot_20220108_144958](https://discourse.vtk.org/uploads/default/original/2X/7/7b54150dca8065bb45f38e1f9cedf236ead8f814.png)

---

<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: [January 9, 2022, 10:43am UTC](https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601/3 "2022-01-09T10:43:45Z")

</div>

Any one can help me to solve this problem ?  
Very thanks any idea !

---

<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: [January 11, 2022, 3:31am UTC](https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601/4 "2022-01-11T03:31:38Z")

</div>

I think I know why this happen .  
In class QQuickVTKRenderItem , it has two function

```auto
  virtual void sync();
  virtual void paint();

```

And all mouse event handled in sync function ,and in this function , it has a variable “ReadyForRendering” and it is always false when Sync() , and when mouse move to a actor like "x " or “Y” or “z” , it called a vtkhardwareSelector to select the path , and it is based on renderwindow’s pixelbuffer , but the pixelbuffer is always null because ReadyForRendering is false and not save pixelbuffers , so vtkhardwareSelector can not select a pixel and cannot get actor by path .  
And in paint() function , it has this part of function :

> this-\>m\_renderWindow-\>SetReadyForRendering(true);  
> if (iren)  
> {  
> iren-\>Render();  
> }  
> else  
> {  
> this-\>m\_renderWindow-\>Render();  
> }
> 
> if (this-\>m\_screenshotScheduled)  
> {  
> this-\>m\_screenshotFilter-\>SetInput(this-\>m\_renderWindow);  
> this-\>m\_screenshotFilter-\>SetReadFrontBuffer(false);  
> this-\>m\_screenshotFilter-\>SetInputBufferTypeToRGB();  
> this-\>m\_screenshotFilter-\>Update();  
> this-\>m\_screenshotScheduled = false;  
> }  
> this-\>m\_renderWindow-\>SetReadyForRendering(false);  
> As you can see , after paint function , the variable ReadyForRendering is set to false again , and the pixelbuffer is null too .  
> So , the reason why it cannot select the actor ,Mainly the problem of this sync and paint process , I don’t think this is an isolated case, I think many future users of qml vtk will encounter this problem.  
> Hope every one can see this and pay attention to this .

---

<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: [January 12, 2022, 12:41am UTC](https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601/5 "2022-01-12T00:41:07Z")

</div>

Okay, finally I solve this problem by replace propicker to cellpicker in vtkcameraorientationwidget .  
Thanks every one .

---

<div class="post-metadata">

### Author: ![heruiyuan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/heruiyuan/32/3770_2.png) [@heruiyuan](https://discourse.vtk.org/u/heruiyuan)
#### Post date: [August 28, 2022, 8:04am UTC](https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601/6 "2022-08-28T08:04:17Z")

</div>

Hi, I got somethin wrong with my vtkcameraorientationwidget in qml, it just like an actor not like a widget:

 ![Capture](https://discourse.vtk.org/uploads/default/original/2X/c/cac22b63cb3607d9f37d189f7179dd3c3d19794d.png)

---

<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: [August 31, 2022, 2:53am UTC](https://discourse.vtk.org/t/vtk9-1-for-qml-with-qquickvtkrenderitem-have-some-issues/7601/7 "2022-08-31T02:53:20Z")

</div>

I think you can see my solved function , change the widget code and replace selector to cellpicker and this will solved. or you can copy a new widget and replace the selector.
