Search code examples
gtkgtkmm3

Gtk widget minimum and maximum width/height with resizable to true


I am new to gtk and using gtkmm-3.0, what i am trying hard is to set the minimum width and height for the gtk widget. I used set_size_request method but the widget is still crossing its min/max size when i resize the parent container.

my code looks like

foo::foo()
{
    set_default_size(400,400); // set default size for window
    add(grid_layout);

    menu_bar.append(file);
    menu_bar.append(edit);
    menu_bar.append(project);
    menu_bar.append(settings);
    menu_bar.append(help);


    right_panel_notebook.insert_page(right_btn, "Page1", Gtk::POS_RIGHT);
    right_panel_notebook.insert_page(notebook_btn, "Page2", Gtk::POS_RIGHT);
    right_panel_notebook.set_size_request(400,300); // setting size for a Notebook widget       


    design_paned.set_vexpand(true);
    design_paned.add1(btn);
    design_paned.add2(right_panel_notebook);


    grid_layout.set_row_homogeneous(false);
    grid_layout.set_column_homogeneous(true);
    grid_layout.attach_next_to(menu_bar, Gtk::POS_RIGHT, 1,1);        
    grid_layout.attach_next_to(design_paned, Gtk::POS_BOTTOM, 1,1);        

    show_all();
}   

So, is there any way to restrict the widget's min/max size with its resizable to true.


Solution

  • Not sure if this is what you want but looking to your code, the set_size_request is being called on the GtkNotebook which is inside a GtkPaned, so:

    GtkPaned childs have two properties, resize and shrink:

    Each child has two options that can be set, resize and shrink . If resize is true, then when the GtkPaned is resized, that child will expand or shrink along with the paned widget. If shrink is true, then that child can be made smaller than its requisition by the user. Setting shrink to FALSE allows the application to set a minimum size. If resize is false for both children, then this is treated as if resize is true for both children

    If shrinkis set to TRUE then the notebook can be smaller that the 400x300 size you've requested.

    To set these properties, use the GtkPanned pack1 and pack2 methods instead of the add1 and add2.