There is a request,a widget has two models,the code look like this
vtkNew<vtkRender> renderA;
//...
vtkNew<vtkRender> renderB;
//...
renderA->SetViewport(0.0, 0.0, 0.5, 1.0);
renderB->SetViewport(0.5, 0.0, 1.0, 1.0);
//use vtk in a Qt project
vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
renderWindow->AddRenderer(renderA);
renderWindow->AddRenderer(renderA);
//widget_vtk is a object of class QVTKOpenGLNativeWidget
widget_vtk->setRenderWindow(renderWindow);
renderWindow->Render();
And then,there are two models in the widget,the left is A, and the right is B. When user mouseclick the left half of widget , i need to know user had choosed A;
And When user mouseclick the right half of widget ,i need to know user had choosed B;
So i implement this function by vtkCommand,like this
public ClickCMD : public vtkCommand{
//.....
virtual Execute(vtkObject* caller, unsigned long eventId, void* vtkNotUsed(callData))override;
};
//.cpp
void ClickModelCMD::Execute(vtkObject* caller, unsigned long eventId, void* vtkNotUsed(callData)) {
if (eventId == vtkCommand::LeftButtonPressEvent) {
std::cout << "MouseLeftClick" << std::endl;
}
//Qt project
vtkNew<ClickCMD > clickCMD ;
widget_vtk->renderWindow()->GetInteractor()->AddObserver(vtkCommand::LeftButtonPressEvent, clickModelCMD);
When i exectue those codes , and click any place of widget(QVTKOpenGLNativeWidget),the termintal awalys show “MouseLeftClick”
But there is a problem,there are two model in widget, how can i know that user click A or B? The only way i can think about is use QMouseEvent(Qt Event),through the QPoint to judge that user click A or B.
Now there are only two models in the same weidget,if i need show more models in the same widget ,this way is not a good idea;
So do you have other better way to know whick model is selected by user click?