Add an observer to the SliceNode's scrollbar


I would like to add an observer to the scrollbar events of a given view. I cannot find the right event to add the callback function.

viewerNode = slicer.util.getNode("vtkMRMLSliceDisplayNode1") # Or should that be the vtkMRMLSliceNode class?
observerID = viewerNode.AddObserver(<WHICH_CLASS__WHICH_METHOD>, onScrollbarChanged)

The callback function:

def onScrollbarChanged(observer,eventID):

Thank you!

So, this will give you the qt object the represents the slider for a particular view (the red slice in this case)

slider ="Red").sliceController().sliceOffsetSlider()

you can then do something like:"Red").sliceController().sliceOffsetSlider().valueIsChanging.connect(lambda x : print(x))

Operating system: Fedora Linux 39
Slicer Version: 5.6.1

The method mentioned by Sam_Horvath valueIsChanging was not working for. I have added an Observer on the slice Logic and it works fine.

sliceLogic =“Red”).sliceLogic()
sliceLogic.AddObserver(vtk.vtkCommand.ModifiedEvent, lambda caller, event: print(“test”))

However, I have noticed that this function will be triggered thrice so you should add a criteria to your function.