GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Treeview problem

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
e-izmir-a
Familiar Face


Joined: 16 Jan 2008
Posts: 8
Location: Schaafheim - Frankfurt / Germany

PostPosted: Sat Jan 19, 2008 10:11 pm    Post subject: Treeview problem Reply with quote

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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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:


after the click:


Can you help me, what there is wrong ?


Thanks,
Ercan
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 480
Location: Portland, OR USA

PostPosted: Sun Jan 20, 2008 4:00 pm    Post subject: Reply with quote

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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP