Hello!
I have a code:
self.scalar_bar = vtkScalarBarActor()
self.scalar_bar_widget = vtkScalarBarWidget()
self.scalar_bar_widget.SetInteractor(self.iren)
self.scalar_bar_widget.AddObserver(vtkCommand.RightButtonPressEvent, self.func)
I want to add some logic after right click at scalarbarwidget but my code dont work. And as i checked only vtkCommand.InteractionEvent works with my code. What kind of error could this be? How to fix it?
Hello,
In C++ I’d do something like this:
(...)
void callbackFunction(vtkObject *caller,
unsigned long vtkNotUsed(QWidget::event),
void *arg,
void *vtkNotUsed(whatIsThis))
{
//envent handling code goes here.
}
(...)
// Set callback for any event
vtkSmartPointer<vtkCallbackCommand> callBackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
callBackCommand->SetCallback( callbackFunction );
callBackCommand->SetClientData((void*)this);
scalar_bar_widget->AddObserver( vtkCommand::AnyEvent , callBackCommand );
This shouldn’t be difficult to translate to Python. Some AI service out there may assist you with that.
best,
PC
Hmm, i tried to impelented this but without succes. I also wanted to use vtkCommand.InteractionEvent and filtr it by interaction event, but still here was only 4 interaction event without right click press event
However, I did something like this:
- I added Observer to iren
- the Observer activates when you right-click.
- the Observer takes the position of the click and checks if it is inside the scalar bar.
- executes xyz if it is.
So, you were able to activate the Observer upon a right-click… I don’t understand your issue, sorry.
I can’t activate Observer by adding it directly to vtkScalarBarWidget, this type of interaction doesn’t work on this widget. I had to do it a little circuitous way and so, the observer is added to vtkRenderWindowInteractor. And my Iren checking if i clicked at Widget(pos of clikcs vs bounds of widget)