[vtkusers] Interactor on vtkWidget

Leonardo M. Ramé l.rame at griensu.com
Tue Sep 21 10:20:09 EDT 2010


Hi, I created a vtkDistanceWidget, and added an observer to catch the
"delete" key on that widget, to be able to delete it from the scene.

The problem is that key events are captured for the whole interactor,
and not for my specific widget. How can I know what was the active
widget at the moment of pressing the delete key?.


This is my code:

void widgetPickObserver(vtkObject* caller, unsigned long eid, void* clientdata, void *calldata)
{
  qDebug(static_cast<vtkRenderWindowInteractor*>(caller)->GetKeySym());
}

void myClass::addDistanceWidget()
{
  distanceWidget = vtkDistanceWidget::New();
  distanceWidget->SetInteractor(this->GetInteractor());
  distanceWidget->CreateDefaultRepresentation();
  static_cast<vtkDistanceRepresentation *>(distanceWidget->GetRepresentation())->SetLabelFormat("%-#6.3g mm");

  vtkSmartPointer<vtkCallbackCommand> Callback = vtkSmartPointer<vtkCallbackCommand>::New();
  Callback->SetCallback(widgetPickObserver);
  Callback->SetClientData(distanceWidget);

  distanceWidget->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, Callback);
  distanceWidget->On();
}


-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com



More information about the vtkusers mailing list