GtkTreeView's row right click

2019-04-30 14:53发布

问题:

How do I do something when user right click in a treeview's row?

回答1:

It's really easy, just listen to the "button-press-event" signal and use treeview.get_path_at_pos() to figure the selected row:

def button_press_event(treeview, event):
    if event.button == 3: # right click
        model, path = treeview.get_path_at_pos(int(event.x), int(event.y))
        # do something with the selected path

treeview.connect('button-press-event' , button_press_event)