简体   繁体   English

无法在 Gtk.TextView i Python 3 中对列进行排序

[英]Cannot sort columns in Gtk.TextView i Python 3

When I try to make my Gtk.TreeView in Python sortable by column I use something like当我尝试使 Python 中的 Gtk.TreeView 可按列排序时,我使用类似

for i, column_title in enumerate(["Title A", "Title B"]):
    renderer = Gtk.CellRendererText()
    column = Gtk.TreeViewColumn(column_title, renderer, text=i)
    column.set_sort_indicator(True)
    column.set_sort_order(Gtk.SortType.ASCENDING)
    column.set_sort_column_id(i)  # trying to make columns sortable
    self.study_view.append_column(column)

but when I click on the title of a column I get the error message但是当我单击列的标题时,我收到错误消息

(main.py:14540): Gtk-CRITICAL **: 22:46:43.573: gtk_tree_sortable_get_sort_column_id: assertion 'GTK_IS_TREE_SORTABLE (sortable)' failed

I've googled the problem but haven't found a solution.我用谷歌搜索了这个问题,但没有找到解决方案。 The docs give no hint.文档没有给出任何提示。 What's wrong?怎么了?

Here's the line in the complete Python application the gives the error message:这是完整的 Python 应用程序中给出错误消息的行:

https://github.com/nordlow/dicom/blob/master/main.py#L241 https://github.com/nordlow/dicom/blob/master/main.py#L241

I'm using these docs as a reference:我使用这些文档作为参考:

https://python-gtk-3-tutorial.readthedocs.io/en/latest/treeview.html?highlight=view#sorting https://python-gtk-3-tutorial.readthedocs.io/en/latest/treeview.html?highlight=view#sorting

This is one of the more complicated pieces of machinery in Gtk.这是 Gtk 中更复杂的机器之一。 You need to wrap the filtered TreeModel with a sorted model, so that you can sort the filtered model again.您需要将过滤后的TreeModel用一个排序TreeModel模型包装起来,以便您可以再次对过滤后的模型进行排序。 Note that a plain TreeModel is sortable before you wrap it with a filtered model.请注意,在使用过滤模型包装之前,普通TreeModel是可排序的。 So your code should look like this on line 225 :所以你的代码在第225行应该是这样的:

self.study_store = StudyStore(client=self.client)
self.current_study_filter = None
self.study_filter = self.study_store.filter_new()
self.study_filter.set_visible_func(self.study_view_filter_func)
self.study_sort = Gtk.TreeModelSort(self.study_filter)
self.study_view = Gtk.TreeView.new_with_model(self.study_sort)

PS I think you are overusing class variables. PS 我认为您过度使用类变量。 No offense please.请不要冒犯。

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

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