gtk:展开小部件,就好像它里面有一些文本一样
我有一个 GTK 小部件,在本例中是一个 TreeView。它一开始非常小并且被压缩,因为除了列名称之外没有任何文本。当我添加内容时,它会水平增长以覆盖文本,并垂直增长以覆盖额外的行。如果我把它们拿走,它会保持其扩大的尺寸。
当您添加内容时,窗口总是会调整大小,这有点烦人。我的问题是 - 如何“预先”调整小部件的大小?就像一种方法是用垃圾文本填充它,我认为这是它可以获得的最大尺寸,然后删除文本,但这看起来不太漂亮。有更好的办法吗?
I have a GTK widget, in this case, a TreeView. It starts off pretty small and compressed, as there's no text in it besides the columns names. As I add things, it grows horizontally to cover the text and vertically to cover the extra rows. If I then take those away, it retains its expanded size.
It's kind of annoying for your window to always be resizing as you add things. My question is - how can I "pre-"size the widget? Like one way would be to fill it with junk text that I think is the biggest size it can get, and then remove the text, but that won't look very pretty. Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
treeview.set_size_request(width, height)
(但是之后你的树视图在需要时不会增长。)expand=True
和fill=True
打包它?window.set_default_size(width, height)
对整个gtk.Window
来说是最好的解决方案,因为正如您所说,“预先”调整了窗口的大小。它仍然可以增长,或者由用户调整得更小。treeview.set_size_request(width, height)
(but then your tree view won't grow when it needs to afterwards.)expand=True
andfill=True
?window.set_default_size(width, height)
on your wholegtk.Window
is the best solution, because that "pre-"sizes the window as you say. It can still grow, or be resized smaller by the user.