[vtkusers] Find out which qVtkWidget the mouse is over
tao sun
colddiesun at gmail.com
Tue May 28 21:38:56 EDT 2013
Hi,
Yes. I have this so far and further more I want to realize a mouseEvent
callback in the main class.
connection = vtkSmartPointer<vtkEventQtSlotConnect>::New();
connection->Connect(this->ui->qvtkWidget_1->GetInteractor(),
vtkCommand::MouseMoveEvent,
this,
SLOT(mouseMoveCallback(vtkObject*,ulong,void*,void*,vtkCommand*)),
NULL,2.0);
void Viewer::mouseMoveCallback(vtkObject * obj, unsigned long,
void * client_data, void *,
vtkCommand * command)
The thing is I have three qvtkWidget and how can I let slot function
know which one's interactor is calling?
Sun Tao
2013/5/28 David Doria <daviddoria at gmail.com>
> On Tue, May 28, 2013 at 8:29 AM, tao sun <colddiesun at gmail.com> wrote:
> > Hi,
> >
> > I overload mouseEvents as functions of the vtkInteractorStyleImage
> subclass.
> > Do you mean I should name a member to indicate the current interactor and
> > QVtkWidget? How could a slot function of the mouseevent know that which
> > QvtkWidget's interactor call it?
> >
> >
> > Thanks,
> > Sun Tao
>
>
> I was talking about something like this:
>
> #include "SideBySideRenderWindowsQt.h"
>
> #include <vtkDataObjectToTable.h>
> #include <vtkElevationFilter.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkQtTableView.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkSphereSource.h>
> #include <vtkCubeSource.h>
> #include <vtkSmartPointer.h>
> #include <vtkInteractorStyleTrackballCamera.h>
>
> // Define interaction style
> class MyInteractorStyle : public vtkInteractorStyleTrackballCamera
> {
> public:
> static MyInteractorStyle* New();
> vtkTypeMacro(MyInteractorStyle, vtkInteractorStyleTrackballCamera);
>
> void SetName(const std::string& styleName)
> {
> this->StyleName = styleName;
> }
>
> virtual void OnMouseMove()
> {
> // Just get the address
> std::cout << "OnMouseMove() in " << this << std::endl;
>
> // Get the "name"
> std::cout << "OnMouseMove() in " << this->StyleName << std::endl;
>
> // Forward events
> vtkInteractorStyleTrackballCamera::OnMouseMove();
> }
>
> private:
> std::string StyleName;
> };
>
> vtkStandardNewMacro(MyInteractorStyle);
>
> // Constructor
> SideBySideRenderWindowsQt::SideBySideRenderWindowsQt()
> {
> this->setupUi(this);
>
> // Sphere
> vtkSmartPointer<vtkSphereSource> sphereSource =
> vtkSmartPointer<vtkSphereSource>::New();
> sphereSource->Update();
> vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
> vtkSmartPointer<vtkActor> sphereActor =
> vtkSmartPointer<vtkActor>::New();
> sphereActor->SetMapper(sphereMapper);
>
> // Cube
> vtkSmartPointer<vtkCubeSource> cubeSource =
> vtkSmartPointer<vtkCubeSource>::New();
> cubeSource->Update();
> vtkSmartPointer<vtkPolyDataMapper> cubeMapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> cubeMapper->SetInputConnection(cubeSource->GetOutputPort());
> vtkSmartPointer<vtkActor> cubeActor =
> vtkSmartPointer<vtkActor>::New();
> cubeActor->SetMapper(cubeMapper);
>
> // VTK Renderer
> vtkSmartPointer<vtkRenderer> leftRenderer =
> vtkSmartPointer<vtkRenderer>::New();
> leftRenderer->AddActor(sphereActor);
>
> vtkSmartPointer<vtkRenderer> rightRenderer =
> vtkSmartPointer<vtkRenderer>::New();
>
> // Add Actor to renderer
> rightRenderer->AddActor(cubeActor);
>
> // VTK/Qt wedded
> vtkSmartPointer<MyInteractorStyle> leftInteractorStyle =
> vtkSmartPointer<MyInteractorStyle>::New();
> leftInteractorStyle->SetName("Left");
>
> vtkSmartPointer<MyInteractorStyle> rightInteractorStyle =
> vtkSmartPointer<MyInteractorStyle>::New();
> rightInteractorStyle->SetName("Right");
>
>
> this->qvtkWidgetLeft->GetInteractor()->SetInteractorStyle(leftInteractorStyle);
>
> this->qvtkWidgetRight->GetInteractor()->SetInteractorStyle(rightInteractorStyle);
>
> this->qvtkWidgetLeft->GetRenderWindow()->AddRenderer(leftRenderer);
> this->qvtkWidgetRight->GetRenderWindow()->AddRenderer(rightRenderer);
>
> // Set up action signals and slots
> connect(this->actionExit, SIGNAL(triggered()), this, SLOT(slotExit()));
> }
>
> void SideBySideRenderWindowsQt::slotExit()
> {
> qApp->exit();
> }
>
> Is that not where you need the information about which window is in use?
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130529/1361466c/attachment.htm>
More information about the vtkusers
mailing list