Gtk 小部件最小和最大 width/height 可调整为 true

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

我是 gtk 的新手,使用的是 gtkmm-3.0,我正在努力尝试为 gtk 小部件设置最小宽度和高度。我使用了 set_size_request 方法,但是当我调整父容器的大小时,小部件仍然超过它的 min/max 大小。

我的代码看起来像

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();
}   

那么,有什么方法可以限制小部件的 min/max 大小,并将其可调整大小设置为 true。

不确定这是否是您想要的,但查看您的代码,正在 GtkPaned 内的 GtkNotebook 上调用 set_size_request,因此:

GtkPaned 孩子有两个属性,resizeshrink:

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

如果 shrink 设置为 TRUE,则笔记本可以小于您请求的 400x300 尺寸。

要设置这些属性,请使用 GtkPanned pack1 and pack2 方法而不是 add1add2