The right way to style row widgets of GtkColumnView

In my GTK4 app, I am trying to style some rows of a GtkColumnView by attaching a style class. The style (e.g., background color) of the row depends on the contents of the first column.

My first attempt was to add the style class to the cells in each row, but the cells have margins, so the styling is not consistent across the row. Hence, I would like to attach the style class to the row widget itself.

In the Gtk inspector, I noticed there are GtkColumnViewRowWidget elements in the object hierarchy, which sounds exactly like the element I would like to target. However, there is no method for me to directly access them and this class is absent from the GTK4 documentation.

GtkColumnView apparently allows to customize rows with a row factory, but because GtkColumnViewRows don’t inherit from Gtk.Widget, it’s missing the add_css_class method.

I could easily get the row by using cell_widget.get_parent() within the bind column callback. If I do this this callback method, the app will crash with no error message. I managed to mitigate this problem by deferring the modification with GLib.idle_add. This way, I successfully attached my CSS class to the row widget and it displays as expected.

However, since GtkColumnViewRowWidget is absent from the documentation and defined in a file called “private” (gtk/gtkcolumnviewrowwidgetprivate.h), I suspect this may be not the right way to do it.

Is there any better way to achieve a consistent styling of the row?