[vtkusers] Find out which qVtkWidget the mouse is over
David Doria
daviddoria at gmail.com
Tue May 28 09:50:21 EDT 2013
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
More information about the vtkusers
mailing list