Frage

I have a table created using gtk.TreeView. I want to know which row and column is selected by the user. How is this possible?

War es hilfreich?

Lösung

The methods for the rows you want are gtk.TreeSelection.get_selected or gtk.TreeSelection.get_selected_rows, depending on the selection method you have chosen (SELECTION_SINGLE, SELECTION_MULTIPLE OR SELECTION_BROWSE).

http://www.pygtk.org/docs/pygtk/class-gtktreeselection.html#method-gtktreeselection--get-selected

For columns you would work with gtk.TreeView.get_path_at_pos

http://pygtk.org/docs/pygtk/class-gtktreeview.html#method-gtktreeview--get-path-at-pos

But you will need more than this method alone, since you need to supply the coordinates for it first. This might give a you a deeper insight in it:

http://www.gtkforums.com/viewtopic.php?f=3&t=2645

get_path_at_pos will return both path and column, so this is probably the method to go for if you really need to know the column that was clicked. So the key to this remains the button press event as listed in the example above and for PyGTK in http://www.pygtk.org/docs/pygtk/class-gdkevent.html

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top