Re: Height of text row in TreeView




On Tue, 2008-04-22 at 23:14 +0000, BJörn Lindqvist wrote:
2008/4/22 amol <amolgkulkarni gmail com>:
>
>  Hi
>  I have a TreeView with two columns one pixbuf and one text.
>  when i have large text in text column the height of text column never
> increase beyond height of pixbuf.

This works for me and I can not reproduce it.
i am attaching a test case and screenshots to reproduce above scenario.
 if i set wrap-width before displaying treeview then it works as
expected and text column height is set accordingly.
 But if i set wrap-width in some timer callback then text gets wrapped
but text column height is not changed.
I have attached screenshots for above two cases.
case 1: (image 1)
  wrap-width is set before doing show.Works as expected.text is wrapped
and height is adjusted accordingly.
case 2: (image 2)
  initially image 2 is displayed as no wrap-width is set but when
wrap-width is set say after 5 sec then image 3 is displayed.text gets
wrapped but height is not adjusted accordingly and we can't see more
than two lines.


>  If there is no pixbuf rendered height never increases beyond one line.

What does this mean? GtkTreeView doesn't word wrap your text unless
you tell it to.

>  Is this issue with GtkCellRendererText?

It is impossible to say. Please provide minimal example code that
demonstrates your problems. Also see bugzilla.gnome.org which is the
standard place for bug reports.


#include <gtk/gtk.h>

  GtkWidget *navigation;
  GtkListStore *liststore;

gboolean callback (gpointer data)
{
  g_message ("in Claback");
  GtkTreeViewColumn *column = (GtkTreeViewColumn *)data;
  GList *cell_list = gtk_tree_view_column_get_cell_renderers (column);
  g_object_set (G_OBJECT (cell_list->data), "wrap-width", 30, NULL);
  g_object_set (G_OBJECT (cell_list->data), "ellipsize", PANGO_ELLIPSIZE_NONE, NULL);
  g_object_set (G_OBJECT (cell_list->data), "wrap-mode", PANGO_WRAP_WORD_CHAR, NULL);
  gtk_widget_queue_resize (navigation);
return FALSE;
}

int
main (int argc, char **argv)
{
  GtkWidget *window;
  GtkTreeViewColumn *column;
  GtkTreeIter it;

  gtk_init (&argc, &argv);

  /* main window */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "delete-event",
                    (GCallback) gtk_main_quit, NULL);
  gtk_window_set_title (GTK_WINDOW (window), "Example");

  liststore = gtk_list_store_new (3, G_TYPE_STRING,GDK_TYPE_PIXBUF,G_TYPE_STRING);
  /* set path to any valid image */
  GdkPixbuf *pixbuf = pixbuf = gdk_pixbuf_new_from_file ("/usr/local/share/celapptests/images/help.png", NULL);
  gtk_list_store_insert_with_values (liststore, &it, 0, 0, "ZZ",1,pixbuf,2,"M", -1);
  gtk_list_store_insert_with_values (liststore, &it, 0, 0, "ZZ",1,pixbuf,2,"M", -1);
  gtk_list_store_insert_with_values (liststore, &it, 1, 0, "AAfs fsd sjs jkbfsj abcdefghijk",1,pixbuf,2,"A", -1);
  gtk_list_store_insert_with_values (liststore, &it, 1, 0, "ZZ",1,pixbuf,2,"M", -1);
  gtk_list_store_insert_with_values (liststore, &it, 1, 0, "ZZ",1,pixbuf,2,"M", -1);
  gtk_list_store_insert_with_values (liststore, &it, 1, 0, "ZZ",1,pixbuf,2,"M", -1);
  gtk_list_store_insert_with_values (liststore, &it, 1, 0, "ZZ",1,pixbuf,2,"M", -1);
  gtk_list_store_insert_with_values (liststore, &it, 1, 0, "ZZ",1,pixbuf,2,"M", -1);
  
  navigation = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore));
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (navigation), TRUE);
  
  column = gtk_tree_view_column_new_with_attributes ("Col1",gtk_cell_renderer_text_new (), "text", 0, NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (navigation), column);

  /* setting  before rendering */
  /* It works but if you comment this it does not even when we are setting it in callback */
#if 0
  GList *cell_list = gtk_tree_view_column_get_cell_renderers (column);
  g_object_set (G_OBJECT (cell_list->data), "wrap-width", 30, NULL);
  g_object_set (G_OBJECT (cell_list->data), "ellipsize", PANGO_ELLIPSIZE_NONE, NULL);
  g_object_set (G_OBJECT (cell_list->data), "wrap-mode", PANGO_WRAP_WORD_CHAR, NULL);
#endif
  g_timeout_add (5000,(GtkFunction)callback,column);

  column = gtk_tree_view_column_new_with_attributes ("Col2",gtk_cell_renderer_pixbuf_new (), "pixbuf", 1, NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (navigation), column);
  
  column = gtk_tree_view_column_new_with_attributes ("Col3",gtk_cell_renderer_text_new (), "text", 2, NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (navigation), column);

  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (navigation), TRUE);
  gtk_container_add (GTK_CONTAINER (window), navigation);
  gtk_widget_show_all (window);
  gtk_main ();

  return 0;
}

Attachment: attachment1.png
Description: PNG image



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]