【发布时间】:2011-05-05 07:48:37
【问题描述】:
我正在学习如何使用 GTKmm,但我很难弄清楚如何将图像放入树视图中。我使用 Glade 创建了一个包含 3 列的树存储,其中之一是名为 store_pixbuf 的 GdkPixbuf。我还在林间空地创建了一个树视图,其中有一列同时包含一个名为 int_col_pict 的 pixbuf 单元格渲染器和一个字符数组单元格渲染器。在我的代码中,我对树存储有通常的 MyColumns 定义,例如:
class MyModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
Gtk::TreeModelColumn<Glib::ustring> store_hostname;
Gtk::TreeModelColumn<Glib::ustring> store_intname;
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > store_pict;
MyModelColumns () { add(store_hostname); add(store_intname); add(store_pict);}
};
并使用以下代码填充它。
//Get a pointer to the treestore
Glib::RefPtr<Gtk::TreeStore> treestore = Glib::RefPtr<Gtk::TreeStore>::cast_static(builder->get_object("routerTreeStore"));
//make sure the pointer isn't bad
if(treestore){
MyModelColumns columns;
//populate the first column
Gtk::TreeRow row= *(treestore->append());
row[columns.store_hostname] = router->hostname;
//populate all children
for(int i=0; i<router->interfaces.size(); i++)
{
//append child row
Gtk::TreeRow child = *(treestore->append(row.children()));
//insert data into the row
child[columns.store_pict] = Gdk::Pixbuf::create_from_file("red_dot.png");
child[columns.store_intname] = router->interfaces[i].interfaceName;
}
}//if
我最初尝试使用股票图像,但我无法弄清楚我应该使用什么功能,所以我尝试使用 Gdk::Pixbuf::create_from_file()(如您在上面看到的),但在运行时我得到了以下错误:
Gtk-WARNING **: gtktreestore.c:765: Unable to convert from GdkPixbuf to gtkmm__GdkPixbuf
Click here 看看它运行的样子。该图像应该与“FastEthernet...”行在同一行
有谁知道我该如何解决这个问题?我完全错了吗?感谢您的关注,感谢您的每一点帮助!
【问题讨论】:
标签: c++ glade gtkmm gtktreeview gdkpixbuf