1. 继承vtkLineWidget2
class myLineWidget2 : public vtkLineWidget2
static void ScaleAction(vtkAbstractWidget*);
2. override the default event bindings
auto eventTranslator =
this->GetEventTranslator(); // override the default event bindings
eventTranslator->RemoveTranslation(vtkCommand::MiddleButtonPressEvent);
eventTranslator->RemoveTranslation(vtkCommand::MiddleButtonPressEvent);
eventTranslator->RemoveTranslation(vtkCommand::RightButtonPressEvent);
eventTranslator->RemoveTranslation(vtkCommand::RightButtonReleaseEvent);
3. 注册新的鼠标事件
this->CallbackMapper->SetCallbackMethod(vtkCommand::RightButtonPressEvent,
vtkWidgetEvent::Scale, this,
myLineWidget2::ScaleAction);
Event Bindings:
By default, the widget responds to the following VTK events (i.e., it watches the vtkRenderWindowInteractor for these events):
If one of the two end points are selected: LeftButtonPressEvent - activate the associated handle widget LeftButtonReleaseEvent - release the handle widget associated with the point MouseMoveEvent - move the point If the line is selected: LeftButtonPressEvent - activate a handle widget accociated with the line LeftButtonReleaseEvent - release the handle widget associated with the line MouseMoveEvent - translate the line In all the cases, independent of what is picked, the widget responds to the following VTK events: MiddleButtonPressEvent - translate the widget MiddleButtonReleaseEvent - release the widget RightButtonPressEvent - scale the widget's representation RightButtonReleaseEvent - stop scaling the widget MouseMoveEvent - scale (if right button) or move (if middle button) the widget