Gtk4 (Toggle) Button with two different images

I need a ToggleButton, currently I have one with an unicode symbol. Not bad, but the toggled state is not that good recognizable. So a toggle button with two different text, unicode-symbols or images would be better. I guess I have to use a plain GtkButton and use add(child) to set content for the two states? May we have an example code for that already?

References: c - How to add an image to a button with GTK4? - Stack Overflow

You could use a one-way binding from the “active” property to the “icon-name” property.

1 Like

Is that for an ordinary GtkButton or a GtkToggleButton? As my guess is that only a GtkToggleButton has an “active” state, but a GtkToggleButton draws the two states itself already in different ways.

Well maybe I should try myself, should be not that hard. Unfortunately Google works so bad for GTK4 currently, that it is not much fun trying new GTK4 stuff. Google was not even able to find the Gtk4 GtkToggleButton API. So one has to remember the GTK API main page, and than navigate further. And my Gentoo-Linux devhelp tool still has no GTK4 support.

Yes, meanwhile I found it :slight_smile:

I guess I should really change my search strategy, using more bookmarks. But in the last years google was so smart, that I just had to type in the full C type name or a C function name and got exactly what I desired. Indeed we should try to use Google less, as for each search the atmosphere is polluted with some CO2. But I think much more important is not to watch videos in internet, which I never do. And all the rest of course, using cars, airplanes, eat much meat… Yes I try.


And maybe I am just too old already, and my memory may be really bad: Some weeks ago I was unable to locate the gobject-introspection API page, tried it for more than ten minutes without success. Then I remembered that the link was stored in – luckily I remembered at least that I had to change it to libgirepository API Reference: libgirepository API Reference

And well, most links in GTK4 for Graphical User Interfaces are broken too.

I use Bing myself and searching for GtkToggleButton gives me:

  • developer-old (gtk3)
  • gtk3
  • gtk4

And indeed for gtk_toggle_button_new_with_label the first result is the gtk4 page for that constructor

Personally I’ve found this whole docs situation quite painful, and still often end up on developer-old, but it does seem search engines in general are starting to catch up for the libraries that have moved to

1 Like

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