# ScalarBarWidget interactor

**URL:** https://discourse.vtk.org/t/scalarbarwidget-interactor/14887
**Category:** Support
**Tags:** python
**Created:** [November 18, 2024, 10:30am UTC](https://discourse.vtk.org/t/scalarbarwidget-interactor/14887 "2024-11-18T10:30:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Mordrago](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mordrago/32/8974_2.png) [@Mordrago](https://discourse.vtk.org/u/Mordrago)
#### Post date: [November 18, 2024, 10:30am UTC](https://discourse.vtk.org/t/scalarbarwidget-interactor/14887/1 "2024-11-18T10:30:12Z")

</div>

Hello!  
I have a code:

```auto
            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?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 18, 2024, 3:04pm UTC](https://discourse.vtk.org/t/scalarbarwidget-interactor/14887/2 "2024-11-18T15:04:20Z")

</div>

Hello,

In C++ I’d do something like this:

```cpp

(...)

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

---

<div class="post-metadata">

### Author: ![Mordrago](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mordrago/32/8974_2.png) [@Mordrago](https://discourse.vtk.org/u/Mordrago)
#### Post date: [November 19, 2024, 10:44am UTC](https://discourse.vtk.org/t/scalarbarwidget-interactor/14887/3 "2024-11-19T10:44:32Z")

</div>

> [@Mordrago](#):
>
> vtkCommand.InteractionEvent

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:

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.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 19, 2024, 11:42am UTC](https://discourse.vtk.org/t/scalarbarwidget-interactor/14887/4 "2024-11-19T11:42:42Z")

</div>

So, you were able to activate the Observer upon a right-click… I don’t understand your issue, sorry.

---

<div class="post-metadata">

### Author: ![Mordrago](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mordrago/32/8974_2.png) [@Mordrago](https://discourse.vtk.org/u/Mordrago)
#### Post date: [November 19, 2024, 11:49am UTC](https://discourse.vtk.org/t/scalarbarwidget-interactor/14887/5 "2024-11-19T11:49:03Z")

</div>

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)
