当前位置: 技术问答>linux和unix
关于gtk tree view,高手给个简单的示例
来源: 互联网 发布时间:2016-01-18
本文导语: 一个窗口,里面放上一个scrollewindow,然后再放上一个gtk_tree_view 里面只显示一列字符串就行了,哪位高手给个简单的示例程序啊? 主要是这个控件不会用啊 | 俺给你写一个 #include char *title[4...
一个窗口,里面放上一个scrollewindow,然后再放上一个gtk_tree_view
里面只显示一列字符串就行了,哪位高手给个简单的示例程序啊?
主要是这个控件不会用啊
里面只显示一列字符串就行了,哪位高手给个简单的示例程序啊?
主要是这个控件不会用啊
|
俺给你写一个
#include
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=%sn",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("%sn",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
#include
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=%sn",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("%sn",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