Treeview with images problem
- From: Remco Poelstra <rjpoelstra home nl>
- To: gtk-app-devel-list gnome org
- Subject: Treeview with images problem
- Date: Fri, 6 Sep 2002 19:56:04 +0200
Hi,
I want to create a TreeView like you see in most file managers. That is
with a pixmap and text on every row. This is what I figured out sofar:
-----------------------------------------------------------#include
<gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *scrolledwindow;
GtkTreeStore *store;
GtkTreeIter iter;
GtkTreeIter child;
GtkWidget *tree;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GdkPixbuf *pixbuf;
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(window),"delete_event",GTK_SIGNAL_FUNC(gtk_main_quit),NULL);
scrolledwindow=gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(window),scrolledwindow);
store=gtk_tree_store_new(1,G_TYPE_STRING);
gtk_tree_store_append(store,&iter,NULL);
gtk_tree_store_set(store,&iter,0,"Bla",-1);
gtk_tree_store_append(store,&iter,NULL);
gtk_tree_store_set(store,&iter,0,"Bla2",-1);
gtk_tree_store_append(store,&iter,NULL);
gtk_tree_store_set(store,&iter,0,"Bla3",-1);
gtk_tree_store_append(store,&child,&iter);
gtk_tree_store_set(store,&child,0,"BWAWAWAWAWA",-1);
tree=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
/*
column=gtk_tree_view_column_new_with_attributes("Blabla",renderer,"text",0,NULL);*/
column=gtk_tree_view_column_new();
renderer=gtk_cell_renderer_pixbuf_new();
pixbuf=gdk_pixbuf_new_from_file("/usr/share/pixmaps/document-icons/gnome-application-pdf.png",NULL);
g_object_set(renderer,"pixbuf",pixbuf,NULL);
gtk_tree_view_column_pack_start(column,renderer,FALSE);
renderer=gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(column,renderer,TRUE);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column);
gtk_container_add(GTK_CONTAINER(scrolledwindow),tree);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
--------------------------------------------------------
But why do I only see pixmaps when I compile this? I think there is
something wrong with my TreeModel, but I don't know what.
Another question is how can I associate the pixmap with the row data so I
get a different pixmap every row?
Thanks in advance,
Remco Poelstra
--
Politics are almost as exciting as war, and quite as dangerous. In war,
you can only be killed once.
-- Winston Churchill
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]