日期:2014-05-16  浏览次数:20778 次

关于gtk tree view,高手给个简单的示例
一个窗口,里面放上一个scrollewindow,然后再放上一个gtk_tree_view
里面只显示一列字符串就行了,哪位高手给个简单的示例程序啊?
主要是这个控件不会用啊

------解决方案--------------------
俺给你写一个
#include <gtk/gtk.h>
char *title[4]={ "ID ", "Name ", "Sex ", "Birth "};
char *student[3][4]={ "1 ", "zhang ", "male ", "1982-5-1 ",
"2 ", "dai ", "female ", "1983-7-8 ",
"3 ", "li ", "female ", "1984-5-8 "};
GtkWidget *window;
GtkWidget *tree;
GtkWidget *sstree;
GtkWidget *subtree;
GtkWidget *fixed;
GtkWidget *clist;
GtkWidget *item1;
GtkWidget *item2;
GtkWidget *item3;
GtkWidget *item4;
void cb_clist(GtkWidget *button,gint row,gint column,GdkEventButton *eb,gpointer data)
{
gchar *text;
gtk_clist_get_text(GTK_CLIST(clist),row,column,&text);
printf( "ROW=%d,Column=%d,text=%s\n ",row,column,text);
}
void cb_select( GtkWidget *item,gpointer data)
{
GtkLabel *label;
char *text;
label=GTK_LABEL(GTK_BIN(item)-> child);
gtk_label_get(label,&text);
printf( "%s\n ",text);
}
int main(int argc,char *argv[])
{
int i;
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(window), "destroy ",
GTK_SIGNAL_FUNC(gtk_main_quit),NULL);
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
gtk_widget_show(window);
fixed=gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window),fixed);
gtk_widget_show(fixed);
clist=gtk_clist_new_with_titles(4,title);
//gtk_container_add(GTK_CONTAINER(window),clist);
gtk_fixed_put(GTK_FIXED(fixed),clist,6,6);
gtk_signal_connect(GTK_OBJECT(clist), "select_row ",
GTK_SIGNAL_FUNC(cb_clist),NULL);
gtk_widget_show(clist);
gtk_widget_set_usize(clist,200,80);
gtk_clist_set_column_auto_resize(GTK_CLIST(clist),2,TRUE);
gtk_clist_set_column_auto_resize(GTK_CLIST(clist),1,TRUE);
for(i=0;i <3;i++)
{
gtk_clist_append(GTK_CLIST(clist),student[i]);
}
tree=gtk_tree_new();
gtk_fixed_put(GTK_FIXED(fixed),tree,6,100);
gtk_widget_show(tree);
gtk_widget_set_usize(tree,200,80);
item1=gtk_tree_item_new_with_label( "Name ");
gtk_signal_connect(GTK_OBJECT(item1), "select ",
GTK_SIGNAL_FUNC(cb_select),NULL);
gtk_widget_show(item1);
gtk_tree_append(GTK_TREE(tree),item1);
item2=gtk_tree_item_new_with_label( "Sex ");
gtk_widget_show(item2);
gtk_tree_append(GTK_TREE(tree),item2);
gtk_signal_connect(GTK_OBJECT(item2), "select ",
GTK_SIGNAL_FUNC(cb_select),NULL);
subtree=gtk_tree_new();
gtk_tree_item_set_subtree(GTK_TREE_ITEM(item1),subtree);
gtk_widget_show(subtree);
item3=gtk_tree_item_new_with_label( "zhang ");
gtk_tree_append(GTK_TREE(subtree),item3);
gtk_signal_connect(GTK_OBJECT(item3), "select ",
GTK_SIGNAL_FUNC(cb_select),NULL);
gtk_widget_show(item3);
sstree=gtk_tree_new();
gtk_tree_item_set_subtree(GTK_TREE_ITEM(item3),sstree);
gtk_widget_show(sstree);
item4=gtk_tree_item_new_with_label( "hua ");
gtk_tree_append(GTK_TREE(sstree),item4);
gtk_signal_connect(GTK_OBJECT(item4), "select ",
GTK_SIGNAL_FUNC(cb_select),NULL);
gtk_widget_show(item4);
gtk_main();
return 0;
}