GNOME Bugzilla – Bug 352594
Setting dimensions for just the viewport of GtkScrolledWindow
Last modified: 2013-02-11 06:42:38 UTC
I think there's a shortcoming when putting a widget into a GtkScrolledWindow where you do not want the latter to expand. For example, I want to add a scrollable GtkTreeView into a GtkFrame. But since the frame is likely to be wider than the width-requisition of the treeview, it would mean that the treeview expands horizontally. But I dont want it to be any wider than its requirement. GtkFrame - GtkHBox -- GtkScrolledWindow --- GtkTreeView So I add first a GtkHBox, and then pack the scrolledwindow with expand=false. However, that makes the GtkScrolledWindow extremely narrow, leaving lots of unused space in the frame. I managed to solve this by listening to the "size-request" signal of the treeview, and then: void size_request_callback (GtkWidget *widget, GtkRequisition *requisition, gpointer user_data) { gtk_widget_set_size_request (widget, requisition->width, -1) } Anyway, this leaves the GtkScrolledWindow with a small forced horizontal scrolling, because though it gets equally wide to the child, there's the vertical scrollbar that eats from that width. It seems very awkward to let the GtkScrolledWindow be just wide enough to show its child, but still add the vertical scrollbar to the width. Sure it's possible to get the vertical scrollbar and get its width, but that is both awkward and unreliable. For example, there's also the "scrollbar-spacing" that affects, and it may change at run-time. So there should be a way to set only the width/height of the viewport area. And then the overall width/height is automatically computed so that min requirement of scrollbars etc are added. Alternatively, there could be a read-only property that gives the min requirements of the GtkScrolledWindow when it has no child. Which could then be used when calculating the overall width/height: width = viewport_width + scrollbars_etc_min_width.
Created attachment 71495 [details] Test case in python
All that is needed is that GtkTreeView (and other widgets with native scrolling) allows a way to reach its GtkViewport, then you can set the width request for the viewport.
I think this was addressed with the min-content-size properties