当前位置: 技术问答>linux和unix
想请问一个gtklist选中行的问题
来源: 互联网 发布时间:2016-06-30
本文导语: 我写了一个gtklist 在选中时要印出选中行的资料 但印出来的都是选中行的上一列 比如说 在list里的资料是 1280x800 1280x768 1024x800 800x600 当我选中1024x800时 印出来的却是800x600 选中1280x768 印出来是1024x800 以下是我的code...
我写了一个gtklist
在选中时要印出选中行的资料
但印出来的都是选中行的上一列
比如说 在list里的资料是
1280x800
1280x768
1024x800
800x600
当我选中1024x800时
印出来的却是800x600
选中1280x768
印出来是1024x800
以下是我的code
烦请大大们帮我解答一下
int dis_ecsapiGetResolution ()
{
FILE *pp;
char str[128];
GtkWidget *list_item;
GList *dlist = NULL;
GtkWidget *clist;
int i = 0;
int temp;
GtkWidget *label;
gchar *string;
//GtkWidget *selected;
//selected = GTK_LIST(list)->selection->data;
system("/root/.ecs/shell/mon_resolution.sh /root/.ecs/config/resolution.st > /root/.ecs/tmp/mon_resolution.st");
pp=fopen(DIS_RESOLUTONPATH, "r");
if (pp == NULL)
{
perror("memory");
return -1;
}
while(!feof(pp))
{
while(fgets(str, 128, pp))
{
str[strlen(str)-1] = str[strlen(str)];
if(!strcmp(str, current_str))
{
temp = i;
//g_print("%dn",i);
}
list_item = gtk_list_item_new_with_label(str);
dlist=g_list_append(dlist, list_item);
gtk_widget_show(list_item);
gtk_object_set_data(GTK_OBJECT(list_item),"a",str);
//label = gtk_label_new(str);
//list_item = gtk_list_item_new();
//gtk_container_add(GTK_CONTAINER(list_item), label);
//gtk_widget_show(label);
//gtk_container_add(GTK_CONTAINER(monitor_list), list_item);
//gtk_widget_show(list_item);
//gtk_label_get(GTK_LABEL(label), &string);
//g_object_set_data(G_OBJECT(list_item),
// "a",
// string);
i++;
}
}
gtk_list_append_items(GTK_LIST(monitor_list), dlist);
gtk_list_select_item(GTK_LIST(monitor_list), temp);
fclose(pp);
}
void mon_select_item(GtkList *list, gpointer *data)
{
int i = 0;
GtkWidget *selected;
GList *dlist;
dlist = GTK_LIST(list)->selection;
while(dlist)
{
//selected = GTK_LIST(list)->selection->data;
GObject *list_item;
list_item = G_OBJECT(dlist->data);
item_data_string = g_object_get_data(G_OBJECT(list_item), "a");
g_print("%s n", item_data_string);
//selected = selected->next;
//g_print("bbn");
dlist = dlist->next;
}
}
monitor_list = gtk_list_new();
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwindow),
monitor_list);
gtk_widget_show (monitor_list);
dis_ecsapiGetResolution();
gtk_signal_connect (GTK_OBJECT (monitor_list), "select_child",
GTK_SIGNAL_FUNC(mon_select_item), NULL);
感激不敬啊
在选中时要印出选中行的资料
但印出来的都是选中行的上一列
比如说 在list里的资料是
1280x800
1280x768
1024x800
800x600
当我选中1024x800时
印出来的却是800x600
选中1280x768
印出来是1024x800
以下是我的code
烦请大大们帮我解答一下
int dis_ecsapiGetResolution ()
{
FILE *pp;
char str[128];
GtkWidget *list_item;
GList *dlist = NULL;
GtkWidget *clist;
int i = 0;
int temp;
GtkWidget *label;
gchar *string;
//GtkWidget *selected;
//selected = GTK_LIST(list)->selection->data;
system("/root/.ecs/shell/mon_resolution.sh /root/.ecs/config/resolution.st > /root/.ecs/tmp/mon_resolution.st");
pp=fopen(DIS_RESOLUTONPATH, "r");
if (pp == NULL)
{
perror("memory");
return -1;
}
while(!feof(pp))
{
while(fgets(str, 128, pp))
{
str[strlen(str)-1] = str[strlen(str)];
if(!strcmp(str, current_str))
{
temp = i;
//g_print("%dn",i);
}
list_item = gtk_list_item_new_with_label(str);
dlist=g_list_append(dlist, list_item);
gtk_widget_show(list_item);
gtk_object_set_data(GTK_OBJECT(list_item),"a",str);
//label = gtk_label_new(str);
//list_item = gtk_list_item_new();
//gtk_container_add(GTK_CONTAINER(list_item), label);
//gtk_widget_show(label);
//gtk_container_add(GTK_CONTAINER(monitor_list), list_item);
//gtk_widget_show(list_item);
//gtk_label_get(GTK_LABEL(label), &string);
//g_object_set_data(G_OBJECT(list_item),
// "a",
// string);
i++;
}
}
gtk_list_append_items(GTK_LIST(monitor_list), dlist);
gtk_list_select_item(GTK_LIST(monitor_list), temp);
fclose(pp);
}
void mon_select_item(GtkList *list, gpointer *data)
{
int i = 0;
GtkWidget *selected;
GList *dlist;
dlist = GTK_LIST(list)->selection;
while(dlist)
{
//selected = GTK_LIST(list)->selection->data;
GObject *list_item;
list_item = G_OBJECT(dlist->data);
item_data_string = g_object_get_data(G_OBJECT(list_item), "a");
g_print("%s n", item_data_string);
//selected = selected->next;
//g_print("bbn");
dlist = dlist->next;
}
}
monitor_list = gtk_list_new();
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwindow),
monitor_list);
gtk_widget_show (monitor_list);
dis_ecsapiGetResolution();
gtk_signal_connect (GTK_OBJECT (monitor_list), "select_child",
GTK_SIGNAL_FUNC(mon_select_item), NULL);
感激不敬啊
|
是不是焦点 切换的问题?
|
GtkList has been deprecated since GTK+ 2.0 and should not be used in newly written code. Use GtkTreeView instead.