Gtk4: label and icons in a stack switcher at the same time

Is there a way to have both labels and icons in a stack switcher? Or any other alternative solution to this using other widgets?

You can set an icon on each of your Stack pages using https://docs.gtk.org/gtk4/method.StackPage.set_icon_name.html

Thank you for your answer but I am aware of the icon name property. I am setting it in the builder xml. The problem is that once we do that the label is not shown anymore. Only the icon remains. I want to have both there but for some reason it seems we are forced to choose if we want a label or an icon…

It is the same thing with buttons. If we set an icon the label disappears. At least in buttons I am able to workaround that by inserting a box containing a label and an image as children. But I have no idea if I can do that in the stackswitcher.

In gtk3 the buttons had a property named like “always-show-image” but it does not exist anymore.

I considered replacing the stackswitcher by radiobuttons but then I faced another difficulty. I just could not figure out how to make radio buttons to look like a togglebutton. In gtk3 this was possible. But I think that the “draw-indicator” property also does not exist anymore.

I then attempted to use togglebuttons directly and it is almost like I want. But there is another problem even after adding the buttons to the same group. It is possible to have a situation where none of the buttons are pressed. What is not what we want in the cases where we would use a stackswitcher. One of the buttons has to be always pressed.

You’ll probably need to use https://exalm.pages.gitlab.gnome.org/libadwaita/doc/main/AdwViewSwitcherTitle.html or https://exalm.pages.gitlab.gnome.org/libadwaita/doc/main/AdwViewSwitcher.html if you want to show both an icon and a label for the stack/view switcher buttons.

Some people recommended me libadwaita. But as I am using gtkmm4 I was hoping some kind of standard gtk4 solution was available…

In gtk4, you can group togglebuttons, to achieve the look you want

Yes. In the end I used togglebuttons

But for some reason putting the togglebuttons in the same group was giving me more problems so I gave up on that. I am managing the group state manually because I could not figure out how to solve the togglebutton group issue I mentioned before.

The “group” property makes sure only one button is pressed. As expected. But in my case it is also needed to make sure that at least one of them is pressed. What usually happens with radio buttons groups. But for some reason this does not happen with togglebuttons.

1 Like