英文:
How to prevent text view from outgrowing window gtk4
问题
假设我在GTK4中有以下布局:一个包含三个子部件的窗口中的垂直框:
其中Text View
的vexpand
属性设置为true
。我遇到了以下问题:当文本视图变得足够大(插入行时),框会扩展超出窗口的大小,将小部件2推出了可见性之外。
如何确保文本视图的大小受到父框/窗口的限制?
从我所看到/找到的信息来看,解决方案可能与大小请求有关,但我不确定如何动态计算文本视图的最大大小。(请注意,我正在努力找到一种方法,以添加多个垂直/水平分隔的文本视图,因此理想情况下,我希望有一种通用解决方案,其中小部件仍然可以根据条件/布局更改而调整大小。
英文:
Suppose I have the following layout in GTK4: A vertical box in a window containing three child widgets:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Widget 1 ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃ ┃
┃ ┃
┃ Text View ┃
┃ ┃
┃ ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃ Widget 2 ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Where The Text View
has the vexpand property set to true. I'm running into the following issue: when the text view gets large enough (by inserting lines), the box expands beyond the size of the window, pushing widget 2 out of visibility.
How can I make sure that the text view is limited in size by the parent box/window?
From what I can see/find, the solution is likely related to size requests, but I'm not sure how to dynamically calculate what the maximum size of the text view should be. (Note that I'm working on a way to add multiple text views which are vertically/horizontally separated, so Ideally I'd like a general solution where the widget can still resize when the conditions/layout change.
答案1
得分: 1
经过一些实验,我找到了一个解决方案。通过将文本视图放置在一个Gtk.ScrolledWindow中,文本视图将会滚动,而不会超出窗口的限制。
这对我来说有点令人困惑,因为Gtk.TextView据说实现了Gtk.Scrollable接口,但我可能误解了这个接口的目的。
英文:
After some experimentation, I've found a solution. By placing the text view in a Gtk.Scrolled Window, the text view will scroll instead of growing beyond the limits of the window.
This is somewhat confusing to me, given that Gtk.TextView supposedly implements the Gtk.Scrollable interface, but I may be misunderstanding the purpose of this interface.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论