Search code examples
c++gtkgtk3gtkmmgtkmm3

TreeView inside ScrollWindow prints warning


Spent 2 days to solve this, so I find this very useful.

I am followed by this GTKmm tutorial, added Gtk::TreeView in Gtk::ScrolledWindow but when I am adding more rows it shows messages like this:

(GUI:25948): Gtk-WARNING **: Allocating size to gtkmm__GtkWindow 0x55ad53e44500 without calling gtk_widget_get_preferred_width/height(). How does the code know the size to allocate?

How to remove warnings? Its annoying too much.


Solution

  • So, you have ExampleWindow class with this childs

    Gtk::ScrolledWindow m_ScrolledWindow;
    Gtk::TreeView m_TreeView;
    Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
    

    Inside your ExampleWindow() constructor replace this:

    m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    

    with:

    m_ScrolledWindow.set_policy(Gtk::POLICY_ALWAYS, Gtk::POLICY_ALWAYS);
    m_ScrolledWindow.set_resize_mode(Gtk::ResizeMode::RESIZE_IMMEDIATE);
    

    I've replaced POLICY_AUTOMATIC with POLICY_ALWAYS because of SIGSEGV in /usr/lib/libgtk-3.so.0