GTKmmの使い方を学んでいて、画像をツリービューに入れる方法を理解するのにとても苦労しています。Gladeを使用して、3つの列を持つツリーストアを作成しました。そのうちの1つはGdkPixbuf
と呼ばれstore_pixbuf
ます。また、呼び出されたpixbufセルレンダラーとint_col_pict
char配列セルレンダラーの両方を含む列を使用して、空き地にツリービューを作成しました。私のコードでは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
実行中の様子を確認するには、ここをクリックしてください。画像は「FastEthernet...」行と同じ行に表示されることになっています
誰かが私がこれを解決する方法を知っていますか?私はそれについて完全に間違っていますか?見てくれてありがとう、少しでも助けてくれてありがとう!