# A problem about choose one model

**URL:** https://discourse.vtk.org/t/a-problem-about-choose-one-model/15611
**Category:** Support
**Created:** [May 13, 2025, 9:02am UTC](https://discourse.vtk.org/t/a-problem-about-choose-one-model/15611 "2025-05-13T09:02:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JXF](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@JXF](https://discourse.vtk.org/u/JXF)
#### Post date: [May 13, 2025, 9:02am UTC](https://discourse.vtk.org/t/a-problem-about-choose-one-model/15611/1 "2025-05-13T09:02:21Z")

</div>

There is a request,a widget has two models,the code look like this

```c++
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

```c++
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?

---

<div class="post-metadata">

### Author: ![Will](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will/32/10487_2.png) [@Will](https://discourse.vtk.org/u/Will)
#### Post date: [May 13, 2025, 9:35am UTC](https://discourse.vtk.org/t/a-problem-about-choose-one-model/15611/2 "2025-05-13T09:35:44Z")

</div>

[examples.vtk.org/site/Cxx/Picking/HighlightPickedActor/](https://examples.vtk.org/site/Cxx/Picking/HighlightPickedActor/)  
It looks like a pickup-related function. This example may help you.

---

<div class="post-metadata">

### Author: ![JXF](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@JXF](https://discourse.vtk.org/u/JXF)
#### Post date: [May 13, 2025, 10:11am UTC](https://discourse.vtk.org/t/a-problem-about-choose-one-model/15611/3 "2025-05-13T10:11:09Z")

</div>

thank you
