如何防止文本视图超出窗口 gtk4

huangapple go评论65阅读模式
英文:

How to prevent text view from outgrowing window gtk4

问题

假设我在GTK4中有以下布局:一个包含三个子部件的窗口中的垂直框:

其中Text Viewvexpand属性设置为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.

huangapple
  • 本文由 发表于 2023年7月13日 20:00:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679131.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定