Custom Drawing on a GtkTreeView



Hi,

I have a treeview whose cells will contain some custom
drawn image. To achieve this, I am making a
treeviewcolumn with pixbuf cellrenderer and I am
capturing "expose-event" of the treeview and then draw
the image on the window. But this doesn't work. If I
don't draw the treeview on the window (i.e., comment
the line "gtk_container_add..." ) then the custom
image is drawn. Can any one help?
Is there any other way to achieve the same?

The code is as below:

gboolean myDraw(GtkWidget *w, GdkEvent *e, gpointer d)
{
 GdkGC *gc = gdk_gc_new(w->window);
 gdk_draw_rectangle(w->window,gc,TRUE,15,15,50,50);
 return TRUE;
}
int main(int argc,char *argv[] )
{
gtk_init (&argc, &argv);
GtkWidget *window;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
GdkColor c;
c.red=65535; c.blue=65535; c.green=65535;
gtk_widget_modify_bg(window,GTK_STATE_NORMAL,&c);
gtk_widget_set_size_request (GTK_WIDGET (window), 300,
300);

GtkTreeView *fTV;
GtkTreeModel *fTM;
GtkTreeStore *fTS;
GtkTreeViewColumn *fTVC;
GtkCellRenderer *ren;

fTS =
gtk_tree_store_new(2,GDK_TYPE_PIXBUF,G_TYPE_STRING);
fTM = GTK_TREE_MODEL(fTS);
fTV =
GTK_TREE_VIEW(gtk_tree_view_new_with_model(fTM));

ren = gtk_cell_renderer_pixbuf_new();
fTVC=
gtk_tree_view_column_new_with_attributes("Custom",ren,"pixbuf",0,NULL);
gtk_tree_view_column_set_min_width(fTVC,100);
gtk_tree_view_column_set_resizable(fTVC,TRUE);
gtk_tree_view_append_column(fTV,fTVC);
ren = gtk_cell_renderer_text_new();
fTVC=
gtk_tree_view_column_new_with_attributes("Text",ren,"text",1,NULL);
gtk_tree_view_column_set_resizable(fTVC,TRUE);
gtk_tree_view_append_column(fTV,fTVC);

GtkTreeIter iter;
gtk_tree_store_append(fTS,&iter,NULL);
gtk_tree_store_set(fTS,&iter,1,"Checkmark",-1);
gtk_tree_store_append(fTS,&iter,NULL);
gtk_tree_store_set(fTS,&iter,1,"NoCheckmark",-1);
	
gtk_widget_show_all(GTK_WIDGET(fTV));

gtk_container_add(GTK_CONTAINER(window),GTK_WIDGET(fTV));

g_signal_connect_after(G_OBJECT(fTV),"expose-event",G_CALLBACK(myDraw),NULL);
gtk_widget_show (window);

gtk_main ();

return 0;
}

Thanks
-Pramod

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



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