Tree item context menu 2

I’ve read the thread “tree item context menu” and i found that the solution there only works if the tree view doesn’t have a scroll bar. When the tree view has a scroll bar and it is scrolled the selection is made like it is not scrolled. Is there a way to solve this?
I’m thinking something like getting the scroll position and then adding it to the position where i will look for the path but i don’t know how to do this.

I’ve solved it by myself with just a call to .getVerticalScrollBar().getValue() to get the scroll position and
adding this result to y coordinate in getRowForLocation and getPathForLocation
Here is the final code:

scroll_position = event.source.getVerticalScrollBar().getValue()
tree = event.source.getViewport().getView()
row = tree.getRowForLocation(event.x, event.y+scroll_position)
path = tree.getPathForLocation(event.x, event.y+scroll_position)
pathStr = “”
if path != None:
for item in path.getPath():
pathStr += str(item) + event.source.separationCharacter
pathStr = pathStr[1:-1]
event.source.setSelectedPath(pathStr)