In my program, I have a GMenu populated with child GMenus. The child GMenus have GMenuItems.
This is what it looks like:
Is it possible to style “pop-up” menus like the one there?
I understand it’s possible to style GTK widgets with CSS but that GMenu is not a GTK widget (unlike the older GtkMenu), and trying to flag the GMenus with CSS names or classes as suggested here predictably doesn’t work: invalid cast from 'GMenu' to 'GtkWidget'
(Specifically, what I’m trying to do is remove any rounded corners or transparency around the “pop-up” menu there.)
Hi! The answer is that yes, you can customize the menu shown in the picture.
A GMenu is just a description of a menu structure that can be either exported to the OS shell (e.g for the macOS app menu bar: What’s in the menu bar on Mac? - Apple Support), or simply make a GtkPopoverMenuBar widget out of it.
What you have in the picture is a GtkPopoverMenuBar widget, made out of a GMenu-based description.
As indicated in Gtk.PopoverMenu, you can style the menu popups with that css:
Note: The margin: 50px; is why the menu in the screenshot’s surrounded by a huge black square. Ordinarily, the black area would be transparent, but I have my desktop environment’s compositor disabled. That disables transparency, rendering the transparent area solid black.
Then, in the callback function connected to my GtkApplication’s activate signal: