On Wednesday 09 February 2005 13:56, Ken Siersma wrote: > I want to specify a number of rows to always display in my > GtkTreeView widget, regardless of how many entities are in my > GtkListStore. I'm using the GtkTreeView to display a list of files. > Sometimes there are no files, sometimes there are 100 files. I want my > GtkTreeView to always display 15 rows. > > I'm porting code from Motif, and Motif can do this simply by specifying > the XmNvisibleItemCount property for it's list widget. I'm looking for > a simple way to do this in GTK as well. I've looked through the API, > but it didn't seem like there were any simple solutions like this.
There isn't really anything as simple as a property. If your rows are all the same height, however, you can probably do this in a hackish way, e.g. by estimating the height of one row, and then multiplying that height with the number of rows you want to be visible, and then call gtk_widget_set_size_request (treeview, -1, height) The tricky thing is to find out the height of a row of course. If you display simple one-line strings or markup, you could do something along these lines: guint simple_estimate_row_height (GtkTreeView *tv) { GtkCellRendererText *cell; PangoLayout *layout; guint row_height, ypad; layout = gtk_widget_create_pango_layout (tv, NULL); pango_layout_set_markup (layout, "<i>red fox jumps bla</i>", -1); pango_layout_get_pixel_extents (layout, NULL, &row_height); cell = gtk_cell_renderer_new_text (); g_object_get (cell, "ypad", &ypad, NULL); g_object_unref (cell); g_object_unref (layout); return row_height + 2*ypad; } I'm sure there are more accurate and less hackish ways, but this might just do anyway. If your treeview is in a scrolled window, you may have to take into account the height of the horizontal scroll bar as well (if it's not set to be invisible). Cheers -Tim _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list