How to setup popover max-width for MenuButton in GTK 4?

I don’t understand is this bug or missed property, but parent level of the popover looks expanded, when at least one sub-menu contains long item labels

image

Hi,

I think it’s because the menu width is calculated from the largest item in all submenus.

You can try using a NESTED menu instead (see Gtk.PopoverMenu:flags), but it’s not adaptive-friendly and plagued with plenty of focus tracking issues.

Or try to limit the size of menu items, e.g. by ellipsizing the labels.

1 Like

Thanks, already ellipsized raw string, because there is no way to get the Label for Popover item (maybe with childs downcast only). Now I think about tooltips, but this feature is not implemented, maybe I need another widget…

Looking at the code, gtk only disables the vertical homogeneity of the menus, not the horizontal one…

You could make some hack like getting the menubutton’s popover, call get_child() till you find the stack, and call set_hhomogeneous(FALSE) on it.

I’ll think about it, maybe it could be worth adding a new gtk API for that…

1 Like