ScalarBarWidget interactor

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 :confused:

However, I did something like this:

  1. I added Observer to iren
  2. the Observer activates when you right-click.
  3. the Observer takes the position of the click and checks if it is inside the scalar bar.
  4. 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)