Hi everyone,
I’am trying to use vtk in a QML project.
I’d like to highlight faces, edges or vertex on the mouse move hover event.
I use VTK 9.3.0.rc1
But it seems that it isn’t implemented in VTK as I can see in QVTKInteractorAdapter::ProcessEvent
Almost every QEvent are handled but not QEvent::HoverMove
.
So I’ve tried a workaround using QML: I put a MouseArea
over my object inherited by QQuickVTKItem
, when the MouseArea
trigger the onPositionChanged
it calls my function that tried to highlight what’s under the mouse using a vtkCellPicker
.
It works for a while but suddenly it randomly crash in some VTK code, most of the time on unverified nullptr…
Here is some QML code:
MouseArea {
anchors.fill: stepViewer
hoverEnabled: true
propagateComposedEvents: true
acceptedButtons : Qt.NoButton
onPositionChanged: {
mouse.accepted = false
myVTKViewer.highlightSubPoly(mouseX, height - mouseY)
}
}
Then the code I use to highlight what I get from the picker:
Nota: vtkPolyData* m_polyData;
// Clear selection
vtkIntArray* cellData = vtkIntArray::SafeDownCast(m_polyData->GetCellData()->GetScalars());
cellData->Fill(UNSELECTED_CELL); // <= value I use to color the unselected cells
...
for (vtkIdType id : triIDS) // <= triIDS contains all cells I want to select
cellData->SetValue(id, HIGHLIGHTED_CELL); // <= value I use to color the highlighted cells
cellData->Modified();
If there is any change in highlighted cells I call scheduleRender();
from my QQuickVTKItem
.
What did I do wrong ?
Is there another way to achieve what I tried to do?