gtk: expand widget as if it had some text in it
I have a GTK widget, in this case, a TreeView. It starts off pretty small and compressed, as there's no te开发者_开发百科xt 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?
- Simplest answer:
treeview.set_size_request(width, height)
(but then your tree view won't grow when it needs to afterwards.) - Is your tree view in a box? Have you tried packing it with
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.
精彩评论