Samantha Catania Samantha Catania - 1 month ago 18
C Question

GtkTreeView homogenous column width

Is there a way to make all the columns in a GtkTreeView have the same width, either programmatically or using Glade/GtkBuilder?


This is an example with 6 columns, it assumes that you use gtk_widget_set_size_request for the treeview widget. I have done here also a size request for the window so the treeview width is equal to that of the window, the following is working for me:

gint width = 650;
gtk_widget_set_size_request (window, width, 550);
gtk_widget_set_size_request (treeview, width, -1);
for (gint i = 0; i < 6; i++) {
  gtk_tree_view_column_set_sizing (columns[i], GTK_TREE_VIEW_COLUMN_FIXED);
  gtk_tree_view_column_set_fixed_width (columns[i], width / 6);

If you resize the window, you will have to calculate sizes again, so you need to capture a resizing event of a window with a signal.

gtk_widget_get_preferred_size () did not return the exact width for me, only an approximate value.