当前位置: 技术问答>linux和unix
在GtkList控件中如何找出选中项(selection)?
来源: 互联网 发布时间:2015-07-25
本文导语: 我的程序是要求就是得到选中的listitem. 我参考了文档 http://www.huihoo.com/gnu/gtk+_FAQ/GTK+_FAQ.htm#AEN662 代码如下:: #ifdef HAVE_CONFIG_H # include #endif #include GtkWidget *list; GtkWidget *hbox; static void cb_select_item(GtkWidget *child, Gtk...
我的程序是要求就是得到选中的listitem.
我参考了文档
http://www.huihoo.com/gnu/gtk+_FAQ/GTK+_FAQ.htm#AEN662
代码如下::
#ifdef HAVE_CONFIG_H
# include
#endif
#include
GtkWidget *list;
GtkWidget *hbox;
static void cb_select_item(GtkWidget *child, GtkWidget *list)
{
GList *items;
items=GTK_LIST(list)->selection;
printf("Selected Items:%s", items);
while (items) {
if (GTK_IS_LIST_ITEM(items->data))
printf("%d ", (guint)
gtk_object_get_user_data(items->data));
items=items->next;
}
printf("n");
}
GtkWidget *create_list (void)
{
GtkWidget *scrolled_window;
GtkWidget *list_item;
int i;
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
gchar *list_items[]={
"Item0",
"Item1",
"foo",
"last Item",
};
gint nlist_items=sizeof(list_items)/sizeof(list_items[0]);
list=gtk_list_new();
gtk_list_set_selection_mode(GTK_LIST(list), GTK_SELECTION_SINGLE);
gtk_container_add(GTK_CONTAINER(hbox), list);
gtk_signal_connect (GTK_OBJECT (list), "select_child", GTK_SIGNAL_FUNC(cb_select_item), list);
gtk_widget_show (list);
for (i = 0; i
我参考了文档
http://www.huihoo.com/gnu/gtk+_FAQ/GTK+_FAQ.htm#AEN662
代码如下::
#ifdef HAVE_CONFIG_H
# include
#endif
#include
GtkWidget *list;
GtkWidget *hbox;
static void cb_select_item(GtkWidget *child, GtkWidget *list)
{
GList *items;
items=GTK_LIST(list)->selection;
printf("Selected Items:%s", items);
while (items) {
if (GTK_IS_LIST_ITEM(items->data))
printf("%d ", (guint)
gtk_object_get_user_data(items->data));
items=items->next;
}
printf("n");
}
GtkWidget *create_list (void)
{
GtkWidget *scrolled_window;
GtkWidget *list_item;
int i;
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
gchar *list_items[]={
"Item0",
"Item1",
"foo",
"last Item",
};
gint nlist_items=sizeof(list_items)/sizeof(list_items[0]);
list=gtk_list_new();
gtk_list_set_selection_mode(GTK_LIST(list), GTK_SELECTION_SINGLE);
gtk_container_add(GTK_CONTAINER(hbox), list);
gtk_signal_connect (GTK_OBJECT (list), "select_child", GTK_SIGNAL_FUNC(cb_select_item), list);
gtk_widget_show (list);
for (i = 0; i