如何在 Gtk 中设置 HPaned 中右窗格的最小和当前大小?
我正在尝试使应用程序窗口在左窗格和右窗格之间具有可移动分隔符。 在左侧窗格中,我有一个 ListView。在右侧窗格中,我有一个带有一些标签、条目等的 VBox。 我添加了 HPaned 容器,将 ListView 添加到其左窗格,将 VBox 添加到其右窗格。 很简单。
问题就来了:
当用户调整窗口大小时,我需要使右窗格保存其大小。虽然,似乎唯一受支持的行为是左窗格执行此操作时。
我需要为右窗格设置一个最小宽度,这样如果用户尝试调整它的大小,它就不会太小,或者,由于第一个问题,只需将窗口大小调整为较小的尺寸。我没有找到任何方法可以做到这一点。实际上,我可以使用 Window.SetGeometryHints() 在右窗格上为 VBox 添加最小约束,但这是唯一的方法吗?所有这些限制都会使窗口在调整大小时变得不稳定。
I am trying to make application window with movable separator between left and right pane.
On the left pane, I have a ListView. On the right pane, I have a VBox with some labels, entries, etc.
I have added HPaned container, added ListView to its left pane and VBox to its right pane.
Pretty simple.
And there goes the problem:
I need to make right pane to save its size when user resizes the window. Although, it seems the only supported behavior is when left pane does so.
I need to set a minimal width for right pane so it will not be too small if the user tries to resize it, or, cuz of first problem, just resizes the window to smaller size. I did not find any way to do that. Actually, I can use Window.SetGeometryHints() to add a minimal constraint for VBox on right pane, but is it the only way to do it? All these constraints make window being jerky when I am resizing it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,经过几次实验,我找到了第一个问题的解决方案。
对于左窗格子项调用 Pack1(widget, true, true) ,对于右窗格子项调用 Pack2(widget, false, false) 就足够了。
第二个问题的解决方案是使用 Window.SetGeometryHints() 为右窗格子项添加 MinSize 约束,但用户似乎无法缩小窗口。
如果有人知道解决第二个问题的正确方法,非常感谢您的帮助。
Okay, after few experiments I found a solution for first problem.
It is enough to call Pack1(widget, true, true) for left pane child, and Pack2(widget, false, false) for right pane child.
Solution for second problem would be to add MinSize constraint for right pane child with Window.SetGeometryHints(), but it seems what the window becomes unshrinkable by user.
If someone knows correct way to solve second problem, your help is very appreciated.
使用 GTK-4.0 和
GtkPaned
,您可以在最后一个子级上使用set_size_request(minimum_width,-1)
和set_shrink_end_size(false)
,因此最终子进程请求最小大小,GtkPaned
会尊重它。要将初始大小设置为最小值,可以使用
set_position(INT_MAX)
。Paned
不会使最终子级小于其请求的大小,因此它会选择最大的可能位置。使用 gtkmm-4.0 的 C++ 示例:
With GTK-4.0 and
GtkPaned
, you can useset_size_request(minimum_width,-1)
on the end child andset_shrink_end_size(false)
, so the end child requests a minimum size and theGtkPaned
respects it.To set the initial size to the minimum, you can use
set_position(INT_MAX)
. ThePaned
will not make the end child smaller than its requested size, so it selects the largest possible position.Example in c++ with gtkmm-4.0: