gtk.treeviewcolumn 不排序
我已经得到了一个可排序的树视图。单击列可按升序排序,再次单击列可按降序排序。但是,如果我第三次单击列标题,它会进入某种“未排序”状态,而不是返回升序。我将一个函数连接到列的 clicked
信号,并打印出列的 get_sort_order()
,每次点击我都会得到 SORT_ASCENDING
升序,SORT_DESCENDING
表示降序,再次 SORT_DESCENDING
表示“未排序”状态。我的树视图构造是这样的:
self.hsModel = gtk.TreeStore(*[c[0] for c in columns])
self.hsModelFilter = self.hsModel.filter_new()
self.hsModelSort = gtk.TreeModelSort(self.hsModelFilter)
#... define filterfunc ...
self.hsModelFilter.set_visible_func(filterfunc)
self.hsSelect = gtk.TreeView(self.hsModelSort)
cl = gtk.TreeViewColumn(ctitle, renderer, **attrcols)
cl.set_clickable(True)
cl.set_sort_column_id(COL_ACTUALTIME)
#... define sortdate ...
self.hsModelSort.set_sort_func(COL_ACTUALTIME, sortdate)
self.hsModelSort.set_sort_column_id(COL_ACTUALTIME, gtk.SORT_DESCENDING)
我永远不想处于这种“未排序”状态。我希望它按升序或降序排序。如何摆脱“未排序”状态?
I've gotten a sortable treeview working. Clicking on the columns makes it sort by ascending order, and clicking it again makes it sort by descending order. However, if I click on the column header a third time, it goes to some "unsorted" state, instead of back to ascending. I connected a function to the clicked
signal of the column, and printed out the column's get_sort_order()
, and for each click I get SORT_ASCENDING
for ascending, SORT_DESCENDING
for descending, and SORT_DESCENDING
again for the "unsorted" state. My tree view construction is something like this:
self.hsModel = gtk.TreeStore(*[c[0] for c in columns])
self.hsModelFilter = self.hsModel.filter_new()
self.hsModelSort = gtk.TreeModelSort(self.hsModelFilter)
#... define filterfunc ...
self.hsModelFilter.set_visible_func(filterfunc)
self.hsSelect = gtk.TreeView(self.hsModelSort)
cl = gtk.TreeViewColumn(ctitle, renderer, **attrcols)
cl.set_clickable(True)
cl.set_sort_column_id(COL_ACTUALTIME)
#... define sortdate ...
self.hsModelSort.set_sort_func(COL_ACTUALTIME, sortdate)
self.hsModelSort.set_sort_column_id(COL_ACTUALTIME, gtk.SORT_DESCENDING)
I never want to be in this "unsorted" state. I want it to either sort by ascending order or descending order. How do I get rid of the "unsorted" state?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
self.hsModelSort.set_default_sort_func(None) 有效,但是您将丢失原始状态(之前的任何排序),如果这是您想要的,那么这就是解决方案,如果您想保留原始形式您必须将默认函数设置为将列排序为原始状态的函数。
很可能您已经首先按降序对值进行排序,因此您只需要执行以下操作:
我希望这能澄清我的观点:
The
self.hsModelSort.set_default_sort_func(None)
works, but you will lose the original state (previous any sort), if is that what you want then thats the solution, if you want to keep the original form you must set the default function to some function that sort the column to the original state.Most likely you already sort the values in descending order in the first place so you just need to do:
I hope this clarify my point:
没有测试,但尝试一下是否
有帮助。默认值只是“使用基础顺序”,但应该可以重置为“根本没有排序功能”状态。
Didn't test, but try if
helps. Default value is just "use underlying order", but should be possible to reset to "no sort function at all" state.