GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Aug 21, 2014 6:17 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Treeview problem
PostPosted: Sat Jan 19, 2008 10:11 pm 
Offline
Familiar Face

Joined: Wed Jan 16, 2008 12:05 pm
Posts: 8
Location: Schaafheim - Frankfurt / Germany
Hello Everybody,
After I have looked 2 hours to find a solution for my problem, am I at my limit :(

I have a treeview Widget, and I want to add some items in it. That was no problem, I have only used this code:

Code:
static GtkTreeModel *
create_liststore (void)
{
   GtkListStore  *store;
  GdkPixbuf     *icon_pos, *icon_neg, *icon_avr, *icon;
  GtkTreeIter    iter;
   int                 i;
   s_date             date;

   /* Loading all icons */
  icon_pos = gdk_pixbuf_new_from_file( get_local_dir("data/icons/", "icon_pos", "png") , &error);
     if (error)
         msg_error(NULL, &errormsg, "Could not load icon", error->message);

  icon_avr = gdk_pixbuf_new_from_file( get_local_dir("data/icons/", "icon_avr", "png") , &error);
     if (error)
         msg_error(NULL, &errormsg, "Could not load icon", error->message);

  icon_neg = gdk_pixbuf_new_from_file( get_local_dir("data/icons/", "icon_neg", "png") , &error);
     if (error)
         msg_error(NULL, &errormsg, "Could not load icon", error->message);

  store = gtk_list_store_new (NUM_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);

   /* Fill */
   gtk_calendar_get_date( GTK_CALENDAR( winMain.calendar ), &date.year, &date.month, &date.day);

   gtk_calendar_clear_marks ( GTK_CALENDAR( winMain.calendar) ) ;

   gtk_list_store_clear (store);   

   for(i = 1; i <= profile_entries.num; i++)
      if( profile_entries.entry[ i ].month == date.month + 1 &&
            profile_entries.entry[ i ].year == date.year &&
            profile_entries.entry[ i ].day == date.day) {

         if( profile_entries.entry[ i ].type == 0) icon = icon_pos;
         if( profile_entries.entry[ i ].type == 1) icon = icon_avr;
         if( profile_entries.entry[ i ].type == 2) icon = icon_neg;

         //gtk_list_store_append (store, &iter);
         gtk_list_store_set (store, &iter,
                              COL_ICON, icon,
                              COL_TITLE, profile_entries.entry[ i ].name,
                                       COL_DES, profile_entries.entry[ i ].text,
                              -1);
   }
 
  return GTK_TREE_MODEL (store);
}
////////////////////////////////////////////////////////////////////////////////////////////////////

void create_treeview()
{
  GtkCellRenderer     *renderer;
  GtkTreeModel        *model;


  /* --- Column #1 --- */

  renderer = gtk_cell_renderer_pixbuf_new ();
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (winMain.view),
                                               -1,     
                                               "  ", 
                                               renderer,
                                               "pixbuf", COL_ICON,
                                               NULL);

  /* --- Column #2 --- */

  renderer = gtk_cell_renderer_text_new ();
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (winMain.view),
                                               -1,     
                                               "Title", 
                                               renderer,
                                               "text", COL_TITLE,
                                               NULL);

  /* --- Column #3 --- */

  renderer = gtk_cell_renderer_text_new ();
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (winMain.view),
                                               -1,     
                                               "Description", 
                                               renderer,
                                               "text", COL_DES,
                                               NULL);

  gtk_tree_view_set_model (GTK_TREE_VIEW (winMain.view), NULL);
  model = create_liststore ();
  gtk_tree_view_set_model (GTK_TREE_VIEW (winMain.view), NULL);
  gtk_tree_view_set_model (GTK_TREE_VIEW (winMain.view), model);

  /* The tree view has acquired its own reference to the
   *  model, so we can drop ours. That way the model will
   *  be freed automatically when the tree view is destroyed */

  g_object_unref (model);
}
//////////////////////////////////////////////////////////////////////////////////////////////

....

void on_change_day     (GtkWidget *calendar,
                       gpointer     user_data)
{
      /* Tree View */
      create_treeview();
}
//////////////////////////////////////////////////////////////////////////////////////////////

...

g_signal_connect (G_OBJECT ( winMain.calendar ), "day-selected-double-click",
            G_CALLBACK (on_change_day), NULL);      


When I click the Calendar widget, to get other Items, It looks terrible:

before the click:
Image

after the click:
Image

Can you help me, what there is wrong ?


Thanks,
Ercan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 20, 2008 4:00 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Are you referring to the columns being added to the treeview? You probably want to empty your list store each time you re-create the view.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group