I am making a GTK3 application with GtkTreeView listing.
The simple listing will show country flags + names and number of radio-channels (to choose from).
I want to show a button or icon in a column (in the cell) when the row has been selected.
Otherwise the cell should be empty (button/icon is hidden).
So I want to show the cell content when row is selected, otherwise hide it (hide the button).
How to do this?
Please be generous with examples and explanation, especially if you refer to CSS and internal layouts of cell renderers.
Here is an example GTK3 application with GtkTreeView (sortable and filterable view) with some data.
The sample shows a “small-arrow.png” icon in the last column. This is the cell I want to hide/show depending on the row is/is not selected.
Sample code: test1.c and small-arrow.png
Get them from:
// Compile and link it
gcc -Wall -o test1 test1.c $(pkg-config --cflags --libs gtk±3.0)
// Run it
You cannot have buttons inside GtkTreeView: it just doesn’t work that way.
If you want to control the visibility of the contents of a cell renderer, you can use a cell data function, or you can bind a column in the model to the cell renderer. You can read more about tree views, models, and cell renderer on the GtkTreeView tutorial. It’s written for GTK2, but the API hasn’t changed.
To be fair, though, it seems you really want a different widget, like a GtkListBox.
As a side note: you really don’t want to show flags inside your UI. Flags are contentious elements, with lots of political implications. Using the wrong flag for the wrong people can be a grave insult. Use the name of the country you’re referring to. It’s a lot easier.
Many thanks for a prompt answer.
The gtk_tree_view_column_set_cell_data_func(…) looks promising.
Of course, double-click event on the row does the same thing for me.
Also a separate button below the tree-view would also work (at least for now).
Both of these will show available radio-channels for the selected country.
User can then search and filter the channels further on.
I may combine this radio-listener application with my audio-recorder via MPRIS2 or via library.
It is an old GTK program that needs refurbishing.
Ok, I will now open a new bottle of wine and then ready to make a test .
I already made a reliable module that loads data from http://www.radio-browser.info/ and puts’em in a GHashTable witk country name as key (or language or station id as key , etc, depending on…)
BTW: Agree with the country flags, but I take my chances. The GUI looks better with flags.
Another issue is that some countries also have local names or translated names. But my tree-view filtering module already handles these issues nicely. I took the country names and flags from Wikipedia.
Muito obrigado (thanks),
Osmo Moma Antero & Bica (dog)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.