在 Gtkmm 中,我想要一个带有 ListStore 的 Gtk TreeView,并且列表中的一列是 ComboBoxText。但我似乎不知道该怎么做。
我目前的情况如下:
class PlayerListColumns : public Gtk::TreeModelColumnRecord
{
public:
PlayerListColumns()
{ add(name); add(team);}
TreeModelColumn<string> name;
TreeModelColumn<ComboBoxText*> team;
}
然后,当设置 TreeView (player_list_view 对象)时,
PlayerListColumns *columns = new PlayerListColumns();
Glib::RefPtr<ListStore> refListStore = ListStore::create(*columns);
player_list_view->set_model(refListStore);
ComboBoxText *box = manage(new ComboBoxText());
box->append("Blah");
box->append("Blah");
box->append("Blah");
TreeModel::Row row = *(refListStore->append());
row[columns->name] = "My Name";
row[columns->team] = box;
“name”列显示得很好,但没有 ComboBox。我几乎肯定,仅仅将一个指向组合框的指针作为列类型是错误的,但我不知道它应该如何进行。我确实收到 GTK 警告:
GLib-GObject-WARNING **:无法从“GtkComboBoxText”类型的值设置类型为“gchararray”的属性“text”
这似乎表明(来自谷歌搜索的一小部分)没有非基本类型的默认渲染器。但我还没有找到任何如何设置的示例(如果这是问题所在)。所有教程仅显示具有原始数据类型的 TreeView。
有人知道如何将 ComboBox 放入 TreeView 中吗?
In Gtkmm, I want to have a Gtk TreeView with a ListStore, and have one of the columns in the list be a ComboBoxText. But I can't seem to figure out how to do it.
What I currently have looks like:
class PlayerListColumns : public Gtk::TreeModelColumnRecord
{
public:
PlayerListColumns()
{ add(name); add(team);}
TreeModelColumn<string> name;
TreeModelColumn<ComboBoxText*> team;
}
Then when setting the TreeView (the player_list_view object)
PlayerListColumns *columns = new PlayerListColumns();
Glib::RefPtr<ListStore> refListStore = ListStore::create(*columns);
player_list_view->set_model(refListStore);
ComboBoxText *box = manage(new ComboBoxText());
box->append("Blah");
box->append("Blah");
box->append("Blah");
TreeModel::Row row = *(refListStore->append());
row[columns->name] = "My Name";
row[columns->team] = box;
The column "name" shows up just fine, but no ComboBox. I'm almost positive that simply having a pointer to a combo box as the column type is wrong, but i don't know how it's supposed to go. I do get GTK warning:
GLib-GObject-WARNING **: unable to set property text' of type
gchararray' from value of type `GtkComboBoxText'
Which seems to indicate (from a small bit of Googling) that there isn't a default renderer for non-basic types. But I haven't been able to find any examples of how to set one up, if that were the problem. All the tutorials only show TreeViews with primitive data types.
Anyone know how to put a ComboBox into a TreeView?
发布评论
评论(1)
好吧,我还没有让它 100% 工作,但是这个示例类应该能让你走上正轨:
http://svn.gnome.org/svn/ gtkmm-documentation/trunk/examples/book/treeview/combo_renderer/
基本上你需要添加一个
Gtk::TreeModelColumn >
到您的列类,并使用Gtk::TreeModelColumn
来保存所选数据。然后,要使列成为组合框,您必须添加:
编辑上面
我认为使用
Gtk::CellRendererCombo*
的方式是在PlayerListColumns
中使用的方法代码>http://developer.gnome.org/gtkmm/stable/classGtk_1_1CellRendererCombo.html
(我还没有进行工作测试,但我从以下地方得到了这个想法:
http://developer.gnome.org /gtkmm-tutorial/unstable/sec-treeview.html.en#treeview-cellrenderer-details)
Okay, I haven't gotten it working 100%, but this example class should get you on the right track:
http://svn.gnome.org/svn/gtkmm-documentation/trunk/examples/book/treeview/combo_renderer/
Basically you need to add a
Gtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> >
to your columns class and aGtk::TreeModelColumn<string>
to hold the selected data.Then, to make a column a combobox, you have to add:
EDIT ABOVE
I think something along the lines of using a
Gtk::CellRendererCombo*
is the way to go in yourPlayerListColumns
http://developer.gnome.org/gtkmm/stable/classGtk_1_1CellRendererCombo.html
(I haven't made a working test yet, but I got the idea from:
http://developer.gnome.org/gtkmm-tutorial/unstable/sec-treeview.html.en#treeview-cellrenderer-details)