get mouse position in gtk scrolled window

1.4k views Asked by At

I have a scrolled window with a viewport, which is some 4000 pixels tall. Is there a way to figure out the mouse position in viewport coordinates? At the moment, what I get for the position is the position in the segment that I actually see, and if I scroll down to the bottom, I still get something like 600 pixels for the vertical position (that is the size of my window), instead of the 4000 that I expect. If there is no easy way, how can one determine by how much the scrolled window is scrolled? I believe, I could then put the pieces together.

Thanks,

v923z

1

There are 1 answers

0
Mark On BEST ANSWER

You are looking for the get_vadjustment method of the scrolled_window.

For instance if you bind the button_press_event to the scrolled window:

def button_press_event(self, widget, event):
    v_scroll_pos = widget.get_vadjustment().get_value()
    print "y pos + scroll pos = %f" % (event.y + v_scroll_pos,)
    return gtk.TRUE

Would print the y position + the amount it is scrolled in the y direction.