GtkColumnView is really not easy

This post is in some form a successor of Editable Cells from gtk4-demo issue

So from the unfixed GTK4 treeview issue and from some remarks in the McLasen blog ( GtkColumnView – GTK Development Blog) I tried to create a compact treeview Gtk replacement with GtkColumnView.

After a dozen hours of work, I have a basically working example now. One of the ugly issues is: To get a compact view looking similar to the old GtkListView/GtkTreeView I can not use big Widgets like GtkEntry, GtkSpinButton or GtkComboBoxText in the GtkColumnView. GtkEditableLable works, but that one has only the “changed” signal from GtkEditable, but not the “activate” signal from GtkEntry which is more useful in most cases. Connecting the changed signal, I get a display update for each user keystroke, when a EditableLabel is modified. That generates a lot of flickering/noise. I tried CSS styling of GtkEntry to make look it tiny, see julia - Make GTK Entry box smaller - Stack Overflow. But no success.

The McLasen blog, API docs, and the tutorials from https://github.com/ToshioCP/Gtk4-tutorial/blob/main/gfm/sec29.md and https://github.com/taozuhong/GtkColumnViewDemo was some help, but still it is very hard.
Another useful example was Reorder rows in a list (GTK4) - #4 by SoongNoonien

It is really interesting how difficult it is to solve such kind of “real world” problems with more recent GTK versions. As there is no “activate” signal for the GtkEditableLabel, I tried some other signals of GtkWidget class, but with no good success. The state-flags-changed signal gave me some hope – then I got the idea to use the changed signal, and query gtk_widget_get_state_flags(). But that does not work, because when connecting the changed signal to a GtkEditableLabel, the changed signal is only emitted when we actually change the string, but not when we hit enter. So GtkEditableLabel is a very weak replacement for GtkEntry. So I have to fall back to GtkEntry in the GtkColumnView, living with the lot of wasted space in the list view. Maybe some CSS tuning will work to shrink it a bit, but I guess it will look always more large and ugly than a plain label. Or maybe I have to revert to the old GTK2 style treeview, with the GtkCritical error message. You may say that I shall just use GtkEntry as that is designed for entering text. But actually, my text strings are only for display in 99% of the time, and have to be edited very rarely only.

I think the reason for all this real world trouble is, that nearly no one actually uses GTK any more. So usability issues, and even bugs may remain undiscovered for decades. And when the one or two experts that we still have here may vanish, then GTK live will even become much harder for the few remaining app creators like me.

And finally, after wasting some hours of my time, I may have found the simple solution: Just use the GtkText widget? I can still not believe that I missed that one.

Use of gtk-inspector for GtkEntry widget showed me the underlying GtkText with a activate signal. Well, I had seen the GtkText widget already some years ago, but did not remembered. Will see if I have some success by use of GtkText widget tomorrow…

I just tested GtkEntry with CSS

entry {
  margin-top: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  border: none;
  min-height: 0px;

as suggested years ago on stack-overflow, but of course that can not work when there is a GtkText child involved.

This is such a troll statement that I’m not even sure how to respond to it in a way that doesn’t devolve in me banning your account from this forum.

The fact that you’re not aware of solutions to your issues, and you don’t have volunteers at your beck and call, does not imply that GTK is unused, or that your problems have never been considered or encountered before. Quite frankly, it’s insulting to the work that people have done over two decades.

I strongly encourage you to move away from GTK, and just use another toolkit.

2 Likes