[vtkusers] QVTKWidget with mouse release

Martijn Koopman koopman.mk at gmail.com
Mon Dec 18 08:30:12 EST 2017


Hi Abdelkhalek,

Where is this code located?
Do you override the function QWidget::mouseReleaseEvent in a subclass of
the QVTKWidget?

I guess not, because ui->qVTK is probably an instance of QVTKWidget.

MouseEvent::pos() returns the position relative to the widget that receives
the event. So, if you override this function in QMainWindow (for example),
then you get a position relative to that widget.

You have three options:
1. map the position relative to the QVTKWidget (Qt may have some helper
functions for this)
2. subclass QVTKWidget and override mouseReleaseEvent there
3. Handle mouse events in VTK.

See also https://lorensen.github.io/VTKExamples/site/Cxx/Interaction/
MouseEventsObserver/ for option 3.

Regards,
Martijn

2017-12-18 11:32 GMT+01:00 Abdelkhalek Bakkari <
bakkari.abdelkhalek at hotmail.fr>:

> Dear All,
>
>
> I am trying to mark on the image using  a mouse release event. But the
> mark appears in different coordinates than which I indicate.
>
> Below is my code:
>
>
> if (event->button() == Qt::LeftButton )
> {
>
> // Seed points visualization
> vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<
> vtkSphereSource>::New();
>
> double center[3] = {event->pos().x(), event->pos().y(), currentSlice};
> qDebug() << "center: " << center[0] << "  "<< center[1] << "  " <<
> center[2];
>
>
> sphereSource->SetCenter(0.0, 0.0, 0.0);
> sphereSource->SetRadius(10.0);
>
> sphereSource->Update();
>
> vtkSmartPointer<vtkPolyDataMapper> sphereMapper = vtkSmartPointer<
> vtkPolyDataMapper>::New();
> sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
> sphereMapper->Update();
>
> vtkSmartPointer<vtkActor> sphereActor = vtkSmartPointer<vtkActor>::New();
> sphereActor->SetMapper(sphereMapper);
> sphereActor->GetProperty()->SetColor(1.0, 0.0, 0.0);
> sphereActor->GetProperty()->SetPointSize(5);
> sphereActor->SetPosition(center);
>
> m_renderer->DisplayToWorld();
> m_renderer->AddActor(sphereActor);
> }
> ui->qVTK1->update();
> -----
>
> Thank you in advance
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://vtk.org/pipermail/vtkusers/attachments/20171218/d2687a9e/attachment.html>


More information about the vtkusers mailing list