首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Vala中用虚拟数据显示GtkTreeView

如何在Vala中用虚拟数据显示GtkTreeView
EN

Stack Overflow用户
提问于 2015-11-24 16:28:45
回答 1查看 178关注 0票数 2

我试图使用Vala在GtkApplication窗口中显示一个带有虚拟数据的GtkApplication。

问题是,窗口似乎是空的,但是在使用GtkInspector仔细查看之后,我可以看到GtkTreeView在那里,但是即使模型已经正确设置,并且它有适当的数据,GtkTreeView看起来也是空的。

到目前为止,我的代码是:

main_window.vala:

代码语言:javascript
复制
using GLib;
using Gtk;

namespace MediaOrganizer
{
    public class MainWindow: Gtk.ApplicationWindow
    {
        /* public constructor(s)/destructor*/
        public MainWindow(string title)
        {
            Object(
                border_width    : 0,
                window_position : WindowPosition.CENTER
            );
            header_ = new Gtk.HeaderBar();
            fileModel_ = new FilesystemModel();
            fileView_ = new Gtk.TreeView();
            mainLayout_ = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);

            this.set_default_size(800, 480);

            header_.set_title(title);
            header_.set_show_close_button(true);
            this.set_titlebar(header_);

            fileView_.set_model(fileModel_);

            this.size_allocate.connect(on_size_changed);

            mainLayout_.add(fileView_);
            add(mainLayout_);
        }

        void on_size_changed(Gtk.Allocation size)
        {
        }

        /* private variables */
        private Box mainLayout_;
        private Gtk.HeaderBar header_;
        private FilesystemModel fileModel_;
        private Gtk.TreeView fileView_;
    }
}

filesystem_model.vala:

代码语言:javascript
复制
using GLib;
using Gtk;

namespace MediaOrganizer
{
    public class FilesystemModel: Gtk.TreeStore
    {
        public FilesystemModel()
        {
            GLib.Type columnTypes[2] = {
                typeof(int),
                typeof(string)
            };
            set_column_types(columnTypes);

            Gtk.TreeIter it;

            append(out it, null);
            set_value(it, 0, 0);
            set_value(it, 1, "aaaa");

            append(out it, null);
            set_value(it, 0, 1);
            set_value(it, 1, "bbbb");

            append(out it, null);
            set_value(it, 0, 2);
            set_value(it, 1, "cccc");
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-24 20:54:13

为商店的每一列添加一个TreeViewColumn:http://valadoc.org/#!api=gtk+-3.0/Gtk.TreeView

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33898895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档