How to obtain popover allocation

Hi, I implemented a toolbar using a few menu buttons on a horizontal box.
Each button opens a popover, and I need to place all popovers at the same location.
In order to do that I implemented a slot for signal_show() call get_allocation() for the middle popover and set the offset to all other popovers, but the allocation x and width are equal to zero.
How can I get the actual screen coordinates of the popover?

You can’t use screen coordinates, and what you’re doing is definitely not a good idea, UX wise.

In any case, my suggestion would be to associate the popover widget to the toolbar itself; whenever you press a button inside the toolbar, you change the menu model of the popover, and pop up the popover widget. This way the popover will stay relative to the same widget.

Hi, thx for your answer!
I’m using Gtkmm4 and my so-cold “toolbar” is a box, how can I “associate the popover widget to the toolbar”? I’m guessing Gtk::Box::appand() won’t help me here…

You need to create your own “toolbar” widget and set a GtkBoxLayout layout manager; then, internally, create a GtkPopover and call gtk_widget_set_parent() on it to make it a child of your toolbar.

1 Like

Thanx! How do I add child widgets to a BoxLayout? I couldn’t find anything here:
https://developer.gnome.org/gtkmm/stable/classGtk_1_1BoxLayout.html#details

You don’t add children to a BoxLayout: you assign a layout manager to your Widget subclass, and you add your children to the widget. A layout manager is a class that knows how to size and position the children of a widget.

Thx! What is the difference between using a BoxLayout and setting a Box as the Widget’s child?

A BoxLayout operates on the children of a widget; a Box is a widget. If you subclass GtkWidget and pack a GtkBox into it, you still need to apply a layout manager, so that the parent GtkWidget knows how to measure its child and allocate a size for it.

Thanks for explaining!

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