deko
deko

Reputation: 495

Gtk+3 How to set cursor on a Gtk.TreeView row?

I'm using Python3 and Gtk+3. When I add a new row to my Gtk.TreeView, these are always appended at the end. I want whenever I add a new row to set the cursor on it. I know I have to use the "set_cursor()" function, or at least I think so. However, I don't know how to retrieve the path of the row.

I am using the signal size-allocate, which tells me when there are changes in my Gtk.TreeView.

self.treeview.connect('size-allocate', self.on_treeview_size_changed)

def on_treeview_size_changed(self, widget, allocation):
    self.treeview.set_cursor(path, None, False)

Any ideas how can I retrieve the path of the last row or make what I am trying to do happen?

Upvotes: 0

Views: 1071

Answers (1)

theGtknerd
theGtknerd

Reputation: 3745

This is what I use:

        last = self.store.iter_n_children ()
        last = last -1  #iter_n_children starts at 1 ; set_cursor starts at 0
        c = self.treeview.get_column(0)     
        self.treeview.set_cursor(last , c, True)    #set the cursor to the last appended item

Basically, get the row count of the store, subtract 1 and set the cursor to that row.

Upvotes: 1

Related Questions