[英]Python - Gtk.TreeView with Gtk.ListStore get selected index
i want to store items in a gtk-list and i decided to use the Gtk TreeView as List. 我想将项目存储在gtk列表中,因此我决定使用Gtk TreeView作为列表。 Because i am quite new to python and gtk i want to store my elements as string representation in the TreeView and in a seperate python-list the according objects.
因为我是python和gtk的新手,所以我想将元素作为字符串表示形式存储在TreeView中,并将相应的对象存储在单独的python-list中。
So if i delete an item in the Gtk list (via key-event), i have to be able to determine the selected row index to delete the correct python-list element. 因此,如果我删除Gtk列表中的一项(通过键事件),则必须能够确定所选的行索引才能删除正确的python-list元素。
My actual question is: How can i determine the index of the selected row in a Gtk.TreeView? 我的实际问题是: 如何确定Gtk.TreeView中选定行的索引?
Thank you for your help! 谢谢您的帮助!
PS: I am using Python 3 with GTK 3 PS:我将Python 3与GTK 3一起使用
Use Gtk.TreeViewSelection. 使用Gtk.TreeViewSelection。 You can get it from Gtk.TreeView (Assuming you have id column in your GtkTreeModel (GtkListStore or GtkTreeStore) constructor).
您可以从Gtk.TreeView获得它(假设您在GtkTreeModel(GtkListStore或GtkTreeStore)构造函数中具有id列)。
from gi.repository import Gtk
def yourcallback ( selection ):
model,list_iter = selection.get_selected ()
if list_iter != None:
# Debugging mode, uncomment to activate
# print "row index = " + model[list_iter][column_number_that_you_want]
# alternate
# def yourcallback (path, column, data):
# ........
..........
yourtvselection = yourtv.get_selection ()
yourtvselection.connect ( "changed" , yourcallback)
# alternative signal
# yourtv.connect ("row-activated", yourcallback)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.