简体   繁体   English

如何将 Gtk.TreeView 的选定行列表作为 int 获取?

[英]How to get the list of selected rows of a Gtk.TreeView as int?

I found that I can get the selected rows like this我发现我可以像这样获得选定的行

model, iters = treeview.get_selection().get_selected()

or like this或者像这样

model, paths = treeview.get_selection().get_selected_rows()

but iters and paths are not lists of int .iterspaths不是int列表。

Is it possible to convert a Gtk.TreeIter or a Gtk.TreePath to int ?是否可以将Gtk.TreeIterGtk.TreePath转换为int

You have to use get_path .你必须使用get_path

if iters is not None:
    row_number = model.get_path(iters)

You can use :您可以使用 :
path, _ = treeview.get_cursor()路径,_ = treeview.get_cursor()
path is a 'TreePath' and not 'int'路径是“TreePath”而不是“int”

indices = path.get_indices()指数 = path.get_indices()
indices is a list of the row numbers : [2 , ...]索引是行号列表: [2 , ...]

indices[0] is the first row number (as integer !) of the selection索引 [0]是选择的第一行号(作为整数!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM