Gtk.TreeView无法添加自定义渲染器,断言'gtk_cell_area_has_renderer(区域,渲染器)'失败

时间:2015-03-23 15:53:05

标签: treeview gtk gtktreeview

我正在尝试通过调用Gtk.Treeview向我的set_attributes添加动态自定义CellRenderer:

    private void add_column (TrackColumns type) {
        var column = new Gtk.TreeViewColumn () ;
        column.title = type.get_title () ;
        var renderer = type.get_cell_renderer () ;
        column.set_attributes (renderer, "text", type) ;

        view.insert_column (column, -1);
    } 

不幸的是,它失败并出现错误

assertion 'gtk_cell_area_has_renderer (area, renderer)' failed

1 个答案:

答案 0 :(得分:1)

在分配渲染器之前,您必须先调用Gtk.TreeViewColumn.pack_start

这是工作代码:

    private void add_column (TrackColumns type) {
        var column = new Gtk.TreeViewColumn () ;
        column.title = type.get_title () ;
        var renderer = type.get_cell_renderer () ;
        column.pack_start (renderer, true);
        column.set_attributes (renderer, "text", type) ;

        view.insert_column (column, -1);
    }