我试图使用Vala在GtkApplication窗口中显示一个带有虚拟数据的GtkApplication。
问题是,窗口似乎是空的,但是在使用GtkInspector仔细查看之后,我可以看到GtkTreeView在那里,但是即使模型已经正确设置,并且它有适当的数据,GtkTreeView看起来也是空的。
到目前为止,我的代码是:
main_window.vala:
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:
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");
}
}
}发布于 2015-11-24 20:54:13
为商店的每一列添加一个TreeViewColumn:http://valadoc.org/#!api=gtk+-3.0/Gtk.TreeView
https://stackoverflow.com/questions/33898895
复制相似问题