Question

I have a program which shows two GtkTreeViews packed inside a GtkPaned (sscce: here):

gtk_paned_add1(GTK_PANED(paned), tree_view1);
gtk_paned_add2(GTK_PANED(paned), tree_view2);

The result is the following:

Window presenting the two tree views

However, the tables can become bigger, so I added then to GtkScrolledWindows (sscce: here):

GtkWidget *scrolled_window1 = gtk_scrolled_window_new(NULL, NULL),
          *scrolled_window2 = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scrolled_window1), tree_view1);
gtk_container_add(GTK_CONTAINER(scrolled_window2), tree_view2);
gtk_paned_add1(GTK_PANED(paned), scrolled_window1);
gtk_paned_add2(GTK_PANED(paned), scrolled_window2);

However, now the window collapses itself to the point it is almost a thin trance, as in the screenshot below:

Insanely small window

If I maximize the window, the first column does not appear (although I can manually expand it):

The first table does not appear

So, what is the best method of getting the appearance of the first screenshot wen using GtkScrolledWindows in this scenario? Also, could I define the size of the pane columns in relation to one another (for example, 30% for the first one, 70% for the second one?

Was it helpful?

Solution 2

The solution I adopted was to actually set the size of the scrolled windows (sscce):

gtk_widget_set_size_request(scrolled_window1, 200, 600);
gtk_widget_set_size_request(scrolled_window2, 600, 600);

The result was, as one would expect, a window with 800x600:

A window with good dimentions

I am not satisfied: this approach relies on arbitrary sizes and it seems too "manual". Nonetheless, I want to use my software so I will adopt it for now.

OTHER TIPS

I've been using this pattern (I'd be happy if someone posted a better answer):

GtkWidget* treeView_, pane1_;
// [Removed code to create and show the widget heirarchy.]
GtkRequisition sizeReq;
gtk_widget_size_request(treeView_, &sizeReq);  // get tree's preferred size
gtk_paned_set_position(GTK_PANED(pane1_), sizeReq.width);

This gets pretty close, but you'll probably have a horizontal scrollbar with a few hidden pixels. Since our application remembers the user's adjustments to the pane positions, it only needs to look "good enough" on initial layout.

Also, there are requirements for gtk_widget_size_request() returning something meaningful. In my case, I've invoked a gtk_widget_show_all() on the hierarchy before retrieving the size request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top