'GtkTreeView: Show all columns

How can I show all the columns of my treeview at my application startup. My treeview has multiple columns:

gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_INT);

But when I run my app, I only see the first two columns (I guess by the packing my window has the minimal size), so I had to scroll to see the rest of the columns. My question is: How can I tell my window to resize itself to ensure all the columns of the treeview are visible?

Update1: Using gtk_widget_get_allocation has no effect, still need to scroll the treeview to see the rest of the columns

GtkAllocation* alloc = g_new (GtkAllocation, 1);
gtk_widget_get_allocation (pAD->treeview, alloc);
gtk_window_set_size_request (GTK_WINDOW (pAD->parent), alloc->width, alloc->height);
g_free (alloc);


Solution 1:[1]

You don't mention which version of GTK you are using, but if you happen to be using GTK3, you might use a combination of an "allocation" object and the "gtk_window_set_default_size" function. As an example, your program could include the following additional code.

GtkAllocation* alloc = g_new(GtkAllocation, 1);

/* your program code prior to displaying the window */

gtk_widget_get_allocation(list, alloc);  /* List name "list" for this example */
gtk_window_set_default_size(GTK_WINDOW(window), alloc->width, alloc->height);

See if that handles your issue.

Regards.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NoDakker