Like Tree1Likes
  • 1 Post By Barney McGrew

GTK in C, Treeview items not showing

This is a discussion on GTK in C, Treeview items not showing within the C Programming forums, part of the General Programming Boards category; I'm working on an app in C with GTK 3, the issue I'm having is my treeviews have blank items, ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    28

    GTK in C, Treeview items not showing

    I'm working on an app in C with GTK 3, the issue I'm having is my treeviews have blank items, the treeviews get filled, but I can't see any text, it's just a bunch of blank items I can select. I created a function so when I click on an item it prints it's value, and it prints the correct value, it's just not displaying the values in the treeview.
    Here's a screenshot:
    Name:  Screenshot from 2013-01-12 09:43:35.png
Views: 315
Size:  4.1 KB

    Here's a little code snippet of how I'm creating my treeviews and adding data:
    Code:
    GtkTreeIter iter;
    GtkCellRenderer *text_cell = gtk_cell_renderer_text_new();
    GtkListStore *library_model = gtk_list_store_new(1, G_TYPE_STRING);
    gtk_list_store_append(library_model, &iter);
    gtk_list_store_set(library_model, &iter, 0, "Item", -1);
        
    GtkWidget *library_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(library_model));
       gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(library_view), 0, "Library", text_cell, NULL);
    Obviously there's more to my code, but that's how I'm creating my treeviews, and adding items to them. Any help is greatly apprecieated

  2. #2
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    467
    This particular forum is for strictly just ANSI C. We don't support libraries here... I'd like to help but I really have no idea why it wouldn't, according to the man page for gtk_list_store_set it looks like you're using it correctly. Try posting in the Linux dev forum.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    981
    I don't know about GTK 3, but in GTK 2.24 (latest maintained version in Windows), there is a "demo" directory in the dev package which demonstrates all widgets. It defines two sample callback functions in particular for your interest: do_tree_store and do_list_store which you can connect into your program.

    I don't do GTK so I could only connect them into the "Hello World" program suggested by the tutorial and they work well enough in this context. As a general approach, why not start from one of these demos and modify it. Then you can compile at stages and see what leads to do the problem.

  4. #4
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    The problem is with your call to gtk_tree_view_insert_column_with_attributes; you're missing two parameters. Try the following:

    Code:
    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(library_view), 0, "Library", text_cell, "text", 0, (void *) 0);
    EDIT: See this for more info.: GtkTreeViewColumn
    Last edited by Barney McGrew; 01-13-2013 at 12:48 AM.
    KoRn KloWn likes this.

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    28
    Quote Originally Posted by Barney McGrew View Post
    The problem is with your call to gtk_tree_view_insert_column_with_attributes; you're missing two parameters. Try the following:

    Code:
    gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(library_view), 0, "Library", text_cell, "text", 0, (void *) 0);
    EDIT: See this for more info.: GtkTreeViewColumn
    This is right, I actually just figured it out after looking at some other examples and playing with my code, well, the only thing I needed to add was "text", not (void *), NULL works just fine, in fact the manpages say to end with NULL. Thanks for all the replies everyone, I always come to this forum for help because it's never failed me

  6. #6
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Well, whether you use NULL or 0 depends entirely on your preference, but it's necessary to explicitly cast both to the target type before passing them as parameters that lack types. See these:

    Question 5.9
    Question 5.11

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Showing & hiding menu items
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-07-2005, 06:28 PM
  2. TreeView
    By StephanC in forum Windows Programming
    Replies: 3
    Last Post: 07-26-2004, 03:14 AM
  3. TreeView
    By StephanC in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2004, 02:15 AM
  4. Problem showing item in TreeView
    By Garfield in forum Windows Programming
    Replies: 4
    Last Post: 03-18-2004, 12:58 AM
  5. Treeview - Win32 API
    By dizolve in forum Windows Programming
    Replies: 1
    Last Post: 11-10-2002, 08:59 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21