2017-10-12 40 views
0

我正在使用Python3和Gtk + 3。 當我添加一個新行到我的Gtk.TreeView時,它們總是附加在最後。 我想要添加一個新行來設置光標。 我知道我必須使用「set_cursor()」函數,或者至少我認爲是這樣。但是,我不知道如何檢索行的路徑。Gtk + 3如何在Gtk.TreeView行上設置光標?

我使用的信號大小分配,它告訴我什麼時候在我的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) 

任何想法如何檢索最後一行的路徑或使我想要做的事情發生?

回答

1

這是我用:

 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 

基本上,拿到店裏的行數,減去1,並設置光標到該行。