Idle_add in Gtk.ColumnViewColumn.setup and .bind

I’m studying this example, which is the only decently complete and still simple example of using ColumnView I could find. I’ve got a bunch of questions regarding this example.

I’d like to understand why the author uses GLib.idle_add in lines 125 and 151, as opposed to run the setup and bind code directly? Is there any benefit to this approach?

Also, coming from Gtk2/3, I wonder why there are no prepackaged shortcuts for this kind of code. I would assume that displaying just a label in a column should be a case so common that a subclass of ColumnViewColumn that just does that would be Gtk4 out of the box? Instead, one needs to manually set up the factory, do all that work with signals and bindings to effectively execute a standard pattern from regular business CRUD applications. it does look quite a bit more complex compared to the “good” old TreeView.

Thank you!

Hi,

TBH, I don’t understand either…

There is one usecase where an idle_add may be relevant, it’s when the data to display in the row is not immediately available, in that case the app can just display a placeholder in bind then update the real data later in idle.
But that method is tricky, as the row widget may be recycled in the meantime.
And even for that scenario, a thread would make more sense than an idle callback.

Well, ColumnView is designed to be very flexible, but the drawback is that it needs a bit more code to use.
I remember I also suffered a lot when creating my first TreeView back in gtk2, it’s a matter of getting used to it.

1 Like