Temple of The Roguelike Forums
Websites => Off-topic (Locked) => Topic started by: Fenrir on November 12, 2009, 02:58:19 AM
-
Anyone here ever worked with GTK-- and Glade? I'm having a hell of a time trying to figure out how to add rows to a TreeView widget. There's plenty of documentation, but none of it seems to relate in any way to what I'm trying to do.
EDIT: I didn't think I should put this in development since I'm not working on a roguelike. Apologies if it's in the wrong place.
-
Haha, I had a very similar experience with Qt and QtDesigner just resently with their idea of TreeView widgets. Oh well, just keep at it I guess. Anyway I have never used GTK, and I guess I wont now Qt is free.
-
Dunno about the Glade side of things, but you can find an example of a treeview in Interhack project (fully turn based multi-player). (http://sourceforge.net/projects/interhack/). Look in src/interfaces/gtkmm.cc. Summary:
The following are the defn:
/* For the inventory list */
class ModelColumns : public Gtk::TreeModel::ColumnRecord {
public:
ModelColumns(void) { add(name); add(obj); add(order); }
Gtk::TreeModelColumn<Glib::ustring> name;
Gtk::TreeModelColumn< Pointer<Object> > obj;
Gtk::TreeModelColumn<unsigned int> order;
} modelColumns;
Gtk::TreeView treeView;
Glib::RefPtr<Gtk::TreeStore> treeStore;
Gtk::TreeModel::Row weapons, armor, food, potions, scrolls,
spellbooks, rings, wands, tools, amulets, gems;
Gtk::Window invWindow;
Gtk::ScrolledWindow invSWindow;
Next we setup the who thing:
/* Inventory Window */
treeStore = Gtk::TreeStore::create(modelColumns);
treeView.set_model(treeStore);
treeView.append_column("Name", modelColumns.name);
treeView.get_column(0)->set_sort_column(modelColumns.order);
invSWindow.add(treeView);
invWindow.add(invSWindow);
invWindow.show_all();
invWindow.set_title("Interhack Inventory");
And finally add some fixed rows:
/* Setup basic groups in inventory window */
weapons = *(treeStore->append());
weapons[modelColumns.name] = "Weapons (";
weapons[modelColumns.order] = 0;
armor = *(treeStore->append());
armor[modelColumns.name] = "Armor [";
armor[modelColumns.order] = 1;
Then when you want to add a sub-row:
Gtk::TreeModel::Row row = *(treeStore->append(spellbooks.children()));
row[modelColumns.name] = "something";
-
I tried getting the Gtk::ListStore object out of Glade, but Gtk::Builder::get_object() returns Glib::Object, so Glib::RefPtr<Gtk::ListStore> pWordList = refBuilder->get_object("wordstore") complains that it can't convert Glib::Object to Gtk::ListStore.
EDIT: A Google search for "gtkmm get_object" revealed that I needed to use Glib::RefPtr<Gtk::ListStore> pWordList = Glib::RefPtr<Gtk::ListStore>::cast_static(refBuilder->get_object("wordstore")). If I can just figure out how to get a Gtk::TreeModelColumn out of the bloody thing I'll be in business.
EDIT AGAIN: Haha! I just had to use set_value().