Reputation: 152
I have a window with a vertical box layout. Within the layout, I've placed three widgets: a menu bar, a notebook and a status bar. The menu bar and the status bar work properly. But the notebook doesn't work as expected: no matter how many tabs I add, it will neither show anything nor append the tab (that is: _notebook->get_n_pages() is always 1).
The code for adding the tab:
Gtk::Label label;
Gtk::TreeView widget;
Gtk::TreeModelColumnRecord colrec;
// Columns are added here to 'colrec'
Glib::RefPtr<Gtk::ListStore> store = Gtk::ListStore::create(colrec);
widget.set_model(store);
_notebook->append_page(widget, label);
Am I missing something? The UI is loaded from a glade file. It is also displayed wrong within Glade because I've removed the default tabs.
Upvotes: 2
Views: 260
Reputation: 891
I'm not 100% sure this is the culprit but for start your Gtk::TreeView
gets destroyed. Try gtkmm manage/add vs smart pointers:.
#include <gtkmm.h>
#include <iostream>
void add(Gtk::Notebook& _notebook)
{
Gtk::Label label;
auto widget = Gtk::manage(new Gtk::TreeView());
Gtk::TreeModelColumnRecord colrec;
// Columns are added here to 'colrec'
Glib::RefPtr<Gtk::ListStore> store = Gtk::ListStore::create(colrec);
widget->set_model(store);
_notebook.append_page(*widget, label);
}
int main()
{
auto Application = Gtk::Application::create();
Gtk::Window window;
Gtk::Notebook notebook;
add(notebook);
add(notebook);
window.add(notebook);
std::cout<<notebook.get_n_pages()<<std::endl;
window.show_all();
Application->run(window);
return 0;
}
Upvotes: 1