How to let GtkMenuButton be flat using GtkBuilder?

If I add the flat CSS style to a GtkMenuButton, the inner GtkToogleButton doesn’t inherits the “flatness”, so it has no effect.

I probably could call gtk_menu_button_get_child() then set the CSS style on it, but is there a way to do this in with GtkBuilder in the XML file?

More important, is this a bug? Adwaita or GTK?

I found the answer minutes after write this :joy:

Just set the has-frame property of GtkMenuButton as the adwaita documentation says so

<property name="has-frame">0</property>

Hm no, .flat should work just fine.

But it didn’t, if it was expected to do so, it’s a bug.

When I add the .flat CSS the inner GtkToogleButton doesn’t inherits the “flatness” and still rendering the frame.

Ah nvm, has-frame is indeed proxied onto the button for GtkMenuButton.

Anyway, screenshot? Maybe it’s dependent on where the button is - could very well be given header bars and such.

A screenshot, with the has-frame on there’s a frame in the MenuButton, even with the flat CSS class. If I set this property to 0 the frame in the inner ToogleButton is gone.

Ah, that’s not libadwaita. That’s an important distinction, because in GTK alone it’s indeed not supported.

So, what libadwaita widget I should be using for this instead of GtkMenuButton? This app already uses libadwaita.

GtkMenuButton, but the important part is libadwaita styles, you’re not using those, so either libadwaita wasn’t initialized, or it’s themes messing it up.

This application is written in Crystal using the GTK4 bindings I’m writing for it plus libadwaita bindings another developer is writting based on my GTK4 bindings.

By initialize libadwaita you mean have the application class inherit from AdwApplication and use AdwApplicationWindow, right? I’m doing exactly this.

If you think just the flat must fix things up (but seems it isn’t), I can create a minimal C code to show the issue in C, to remove the change of having this due to bugs in the bindings.

inherit from AdwApplication

That’s one way, sure. Then you have GTK_THEME set to something and libadwaita styles don’t load.

to remove the change of having this due to bugs in the bindings.

There’s 0 chance of that, we’re talking about css and I know it’s not there in gtk default styles, and I can see from your screenshot it’s not libadwaita styles.

Hmmm, but I have the environment variable set.

$ export | grep GTK
declare -x GTK_THEME="Adwaita:dark"

I’m using official ArchLinux packages

  • libadwaita 1.3.2
  • Gnome 44
  • gtk4 4.10.3

Better create a one-file C source to reproduce the issue, so we can check if it’s a problem with my environment or a libadwaita bug.

Yes, that’s what breaks it. Don’t set it. :woman_shrugging:

After few days I remembered to remove the environment variable and… you are right! it worked fine… and also solved things I though was render bugs in Nautilus.

Thanks very much.

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