TreeView里加的按钮不能按
- #include <gtk/gtk.h>
- enum
- {
- CHECK_BTN=0,
- COL_NAME,
- COL_AGE,
- NUM_COLS
- } ;
- static GtkTreeModel *
- create_and_fill_model (void)
- {
- GtkListStore *store;
- GtkTreeIter iter;
- store = gtk_list_store_new (NUM_COLS,G_TYPE_BOOLEAN,G_TYPE_STRING, G_TYPE_UINT);
- /* Append a row and fill in some data */
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- CHECK_BTN,TRUE,
- COL_NAME, "Heinz El-Mann",
- COL_AGE, 51,
- -1);
- /* append another row and fill in some data */
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- CHECK_BTN,FALSE,
- COL_NAME, "Jane Doe",
- COL_AGE, 23,
- -1);
- /* ... and a third row */
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- CHECK_BTN,TRUE,
- COL_NAME, "Joe Bungop",
- COL_AGE, 91,
- -1);
- return GTK_TREE_MODEL (store);
- }
- GtkWidget *create_window()
- {
- GtkCellRenderer *renderer;
- GtkTreeModel *model;
- GtkWidget *view;
- GtkWidget *window;
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (window, "delete_event", gtk_main_quit, NULL); /* dirty */
- view = gtk_tree_view_new ();
- /* --- Column #1 --- */
- renderer = gtk_cell_renderer_toggle_new();
- // g_object_set(G_OBJECT(renderer),"activatable",TRUE);
- gtk_cell_renderer_toggle_set_active(GTK_CELL_RENDERER_TOGGLE(renderer),FALSE); gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(renderer),FALSE);
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view), -1,"按钮", renderer, "active",CHECK_BTN,NULL);
- /* --- Column #2 --- */ renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view), -1,"Name", renderer, "text", COL_NAME, NULL);
- /* --- Column #3 --- */
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view), -1,"Age", renderer, "text", COL_AGE,NULL);
- model=create_and_fill_model ();
- gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
- /* The tree view has acquired its own reference to the
- * model, so we can drop ours. That way the model will
- * be freed automatically when the tree view is destroyed */
- gtk_container_add(GTK_CONTAINER(window),view);
- return window;
- }
- int
- main (int argc, char **argv)
- {
- GtkWidget *window;
- gtk_init (&argc, &argv);
- window= create_window();
- gtk_widget_show_all (window);
- gtk_main ();
- return 0;
- }
复制代码
我在里面加了个按钮但是怎么按也按不动不知道为什么
初学GTK请老鸟指教
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经知道了
不过还是谢谢版主告诉我这个好东西,如果有这东西那还用去问人呀
哈哈
请运行 gtk-demo 程序,然后查看 Tree View -> List Store 的源程序,就应该知道怎么处理了。