我正在使用GTK4.8.3构建一个图形用户界面应用程序.我想要两个ScrolledWindow
,其中一个(包含ListBox
)可以水平扩展,而另一个(包含Button
)不能.更准确地说,我想将按钮的功能限制在hexpand
.
从GTK文档中,我知道有Setting hexpand
explicitly will override the automatic expand behavior个.
当我使用下面的代码片段创建小部件并try 限制水平扩展时,我的按钮仍然可以水平扩展,以及它的父ScrolledWindow
.为什么会出现这种情况?我如何才能修复它?
let hyphens_scrollbox = ListBox::builder()
.width_request(windows::WIDTH)
.hexpand(true)
.build();
let hyphens_scrollwindow = ScrolledWindow::builder()
.width_request(windows::WIDTH)
.height_request(customising::SCROLL_HEIGHT)
.hexpand(true)
.vexpand(true)
.hscrollbar_policy(PolicyType::Never)
.vscrollbar_policy(PolicyType::Always)
.child(&hyphens_scrollbox)
.build();
let details_scrollwindow = ScrolledWindow::builder()
.width_request(windows::WIDTH)
.height_request(entries::CONTAINER_HEIGHT)
.hscrollbar_policy(PolicyType::Never)
.vscrollbar_policy(PolicyType::Automatic)
.hexpand(false)
.child(&details_scrollbox)
.build();
let new_button = Button::builder()
.label("Add new group")
.margin_bottom(buttons::MARGIN)
.hexpand(false)
.build();
details_scrollwindow.append(&new_button);
let defaultsbox = GtkBox::builder()
.orientation(Orientation::Vertical)
.width_request(windows::WIDTH)
.build();
defaultsbox.append(&hyphens_scrollwindow);
defaultsbox.append(&details_scrollwindow);