代码之家  ›  专栏  ›  技术社区  ›  Nordlöw

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

  •  2
  • Nordlöw  · 技术社区  · 8 年前

    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)
    

    但是当我点击一个列的标题时,我得到了错误信息

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

    我用谷歌搜索了这个问题,但没有找到解决办法。医生没有暗示。发生了什么?

    下面是完整Python应用程序中的一行,给出了错误消息:

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

    我使用这些文档作为参考:

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

    1 回复  |  直到 8 年前
        1
  •  1
  •   Nordlöw    8 年前

    这是Gtk中较复杂的机械部件之一。你需要把过滤过的东西包起来 TreeModel 树模型 在使用过滤模型包装它之前是可排序的。所以你的代码应该是这样的 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)
    

    另外,我认为你过度使用了类变量。无意冒犯。