ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
For some reason my treeview isn't displaying the data I just added to my liststore. I've looked at countless examples and THINK my code seems fine, but for some reason the one and ONLY one line of dummy data I've added to my liststore doesn't apear on my treeview.
Now, the columns come out fine, but the line of foo data that I'm adding as a test, is nowhere to be found. It worked just great for my combobox and all the examples that I've looked at does very much the same as my own code, but somewhere along the line the foo data goes awol.
I should add that I did the GUI layout in Glade. I did notice with the api docs that you can only use some of the api calls on a widget that was created using a specific api call, in this case it would have been gtk_tree_view_new_text(...), or something simmilar, but none of the calls i'm using specify this caveat, so I've dicounted that as an issue.
I've also tried re-connecting the liststore to my treeview, just on the off-chance that it made a difference.
So...
1) connect liststore to treeview
2) set liststore data
3) connect liststore to treeview
So, the problem was that apparently the gtk+ api uses the column of the treeview widget to reserve columnar space for cellrenderers and it's the cellrenderers that display the text. So, it was quite happy with my code, and was happy to except all my data, but wouldn't, and as it turns out couldn't, display any of it. So I've now added a shared cellrender for all the columns and all my data now displays quite happily.
So, for those coming to this later, here's what works for me.
Code:
/*
I used ONE cell renderer for ALL columns and it seems to work fine for me.
I can't ascertain if this legal or not, but so far so good.
I have NO doubt there will be time where this just won't do.
*/
/* Define and append columns. */
cr_0 = gtk_cell_renderer_text_new(); /* The new cell renderer */
col_year = gtk_tree_view_column_new_with_attributes ("ID", cr_0, NULL);
/*
ARGS (the column, cellrenderer, "attribute", column to associate cell attribute with)
The list is NULL terminated.
*/
gtk_tree_view_column_set_attributes (col_year, cr_0, "text", 0, NULL);
gtk_tree_view_column_set_min_width ( col_year, 100 );
gtk_tree_view_append_column ( tvw_wage_list, col_year );
/*
This is one column. I've obviously done that for every column, using the SAME cell render.
*/
BUT!!!!!
For it to display the values, I had to attach the text attribute of the cellrender to the columns....one at a time....I suppose I will have to do so everytime I restructure the treeview widget (as the treeviewwidget structure depends on the data passed).
I really can't understand why the treeview column widget couldn't just have a standard cellrenderer attached to it by default, where all attributes for the cell renderer would be connected to the column attributes....by default. So that you could set text, alignment etc for the treeview column and it would trickle down to the cellrenderer by default. I would have thought that in at least 80% of the time, everyone would be happy with that. If you do need to change separate attributes for the cellrenderers, you could do something like gtk_tree_view_get_cell_renderer(...), or something.
You could take it even further. Why not have this....
Code:
/* I need a new GtkTreeView widget with 5 Columns each labeled accordingly. */
gtk_tree_view_new (num_columns, ..., attributes, ....);
GtkTreeView *tree = gtk_tree_view_new_with_attributes (
3,
"ID", "First Name", "Last Name",
"alignment", 0.5, "min-width", 80, "expand", FALSE, NULL
);
This way you could have default columns and cellrenders all connected to each other. Again, if you wanted to go further you could, just fetch a column or cellrenderer etc.
Then it came to setting the alignment on the columns. All i really would have wanted to do was the following...
The reason I wanted to do that, was because that is what you would have done in glade/name-your-ide, but apparently not. This also seems to comply with the API docs which expects a float ... sorry ... gfloat. The worst thing is, I don't even know why it doesn't work, but I get a segfault somewhere all the way down in strlen(), which seemed a bit weird as we're using gfloat. So, I tried using "0.5". That seemed alright, except the change didn't show. So I was sure that must be because I needed to sync my cellrender.......erm....no.
Code:
unable to set property `alignment' of type `PangoAlignment' from value of type `gchararray'
So, I tried PANGO_ALIGN_CENTER, and I tried (gfloat)0.5 and, and , and.....
Each fails in it's own special little way.
OK.
Now, I know I've been moaning a lot here, but really, I've just been venting a little bit. I LIKE gtk+, I really do. It's a lot lighter than Qt, it's prettier than fltk (i like fltk too), it's stable and just generally GREAT. But please guy's, show me the light. Show me where I'm going wrong with this.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.