Here is all of the code that I have been using to try and achieve this. It's already pretty simple, as I never really have gotten anywhere since I cannot seem to figure out how to get anything to be filled into the TreeView widget. On Sun, 2008-02-17 at 14:29 -0600, Jonathon Jongsma wrote: > On Sun, 2008-02-17 at 12:28 -0500, Ryan Lovelett wrote: > > > > Hello, > > > > I subscribed to this mailing list last week in hopes of seeing > > something similar asked and solved so I could apply it to my project. > > I didn't so here is my question. > > > > I'm creating a TreeView from within Glade 3 (so I'm getting an XML > > file). I load and display the designed UI just fine from my > > kit.run(*MainDialog) call. Now, I want to start adding stuff to the > > TreeView at runtime (in otherwords user input data, etc). So I've set > > up the ModelColumns as described in > > (http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/chapter-treeview.html#sec-treeview-model). They display just fine and I see my column headings. Superb! > > > > Now my problem. If I am to understand how you add new columns you > > call: > > > > Gtk::TreeModel::Row row = *(instanceofTreeModel->append()); > > row[ModelColumnInstance.col] = "TextToDisplay"; > > > > Super, but nothing ever gets displayed on the screen after appending > > the new information to the TreeStore. If I put that call before my > > kit.run(*MainDialog); it displays the information as expected. It's > > almost like the TreeView widget needs to be re-drawn on screen for the > > data to show. Is there some call that needs to be made that forces > > the re-draw of the TreeView? Also, if you need and or want to see the > > full code just ask. > > I think that in order to make any informed recommendations we'd need to > see some code. If possible, the code sample should be as simple as > possible (and in paring down your example to a simple test case, you > might even find the problem somewhere)
Attachment:
browse.glade
Description: application/glade
#ifndef INTERFACE_H_INCLUDED #define INTERFACE_H_INCLUDED #include <gtkmm.h> // Tree model columns for the display of the data for a given repository class ModelColumns : public Gtk::TreeModel::ColumnRecord { public: ModelColumns(); Gtk::TreeModelColumn<Glib::ustring> file_name; Gtk::TreeModelColumn<Glib::ustring> file_ext; Gtk::TreeModelColumn<int> revision; Gtk::TreeModelColumn<Glib::ustring> author; Gtk::TreeModelColumn<Glib::ustring> size; Gtk::TreeModelColumn<Glib::ustring> date; Gtk::TreeModelColumn<bool> locked; }; /** * Default constructor for the ModelColumns object. * Adds the m_col_id and m_col_name members to the ColumnRecord */ ModelColumns::ModelColumns() { add(file_name); add(file_ext); add(revision); add(author); add(size); add(date); add(locked); } ModelColumns m_Columns; Glib::RefPtr<Gtk::TreeStore> m_refTreeModel; #endif // INTERFACE_H_INCLUDED
#include <libglademm/xml.h> #include <gtkmm.h> #include <iostream> #include <interface.h> #define REPO_BROWSER_LOCATION "browse.glade" #define REPO_BROWSER_NAME "RepoBrowser" #define REPO_TREEVIEW_NAME "revision_treeview" Gtk::Window* MainDialog = 0; Gtk::TreeView* revTreeView = 0; void on_button_clicked() { if(MainDialog) MainDialog->hide(); //hide() will cause main::run() to end. } /** * This method loads the Glade file that describes the browse application dialog. * Then assigns handlers for all the signals created by a user. */ int main (int argc, char **argv) { Gtk::Main kit(argc, argv); //Load the Glade file and instiate its widgets: Glib::RefPtr<Gnome::Glade::Xml> refXml; #ifdef GLIBMM_EXCEPTIONS_ENABLED try { refXml = Gnome::Glade::Xml::create(REPO_BROWSER_LOCATION); } catch(const Gnome::Glade::XmlError& ex) { std::cerr << ex.what() << std::endl; return 1; } #else std::auto_ptr<Gnome::Glade::XmlError> error; refXml = Gnome::Glade::Xml::create(REPO_BROWSER_LOCATION, "", "", error); if(error.get()) { std::cerr << error->what() << std::endl; return 1; } #endif //Get the Glade-instantiated Dialog: refXml->get_widget(REPO_BROWSER_NAME, MainDialog); if(MainDialog) { //Get the Glade-instantiated Button, and connect a signal handler: Gtk::Button* pButton = 0; refXml->get_widget("ok_button", pButton); if(pButton) { pButton->signal_clicked().connect( sigc::ptr_fun(on_button_clicked) ); } refXml->get_widget(REPO_TREEVIEW_NAME, revTreeView); //Create the Tree model: m_refTreeModel = Gtk::TreeStore::create(m_Columns); revTreeView->set_model(m_refTreeModel); revTreeView->append_column("File", m_Columns.file_name); revTreeView->append_column("Extension", m_Columns.file_ext); revTreeView->append_column("Revision", m_Columns.revision); revTreeView->append_column("Author", m_Columns.author); revTreeView->append_column("Size", m_Columns.size); revTreeView->append_column("Date", m_Columns.date); revTreeView->append_column("Locked", m_Columns.locked); kit.run(*MainDialog); } Gtk::TreeModel::Row row = *(m_refTreeModel->append()); row[m_Columns.file_name] = "file name"; row[m_Columns.file_ext] = "dir"; MainDialog->show_all_children(true); return 0; }