GTK4: How to set a GtkBox to "toolbar" style class

Hi, the GTK 3 to 4 migration guide mentions that toolbars are gone and that a GtkBox with the
style class set to “toolbar” should be used.
How can this be done from within a C program, without using a UI or XML file? I googled for hours,
but couldn’t a find solution. It is probably very simple, but I’m still learning GTK, so a simple C example
would be very much appreciated.

Ralf

gtk_widget_add_css_class (toolbar, "toolbar");

@jensgeorg It works, thanks. That was what I was looking for.

Ralf

I googled for hours, but couldn’t a find solution.

Google is pretty much useless for helping with GNOME/GTK development. I found an app called DevHelp that actually helps.

1 Like

Related to this topic, for toolbars being implemented with GtkBox.

With GTK 3 and GtkToolbar, when the window is resized to a smaller size, the toolbar has a drop-down menu at the end to still access toolbar items that cannot be shown.

So I think with GtkBox you will run into this problem.

It is not difficult to re-implement a similar drop-down behavior in GTK4 but this is probably not what you want when using libadwaita, one of the adaptive containers will probably work better for a small screen size.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.