Single Popover menu on multiple widget objects (reparenting)

I am trying to create a single GtkPopover instance (with a menu) that I can use across different widget objects. However, it consistently appears on the widget object where it was first displayed. I attempted to reparent it each time, but that didn’t seem to work. I also noticed that gtk_popover_set_relative_to was available in GTK3, but this method doesn’t exist in GTK4.

Here’s the code I’m using:

GtkPopover* popOver = GTK_POPOVER(pContextMenuNatHandle);

// Reparent the popover to the new widget
gtk_widget_set_parent(GTK_WIDGET(popOver), parent);

// gtk_popover_set_relative_to(popOver, parent); // GTK3 only

GdkRectangle rect = { (int)pointOnFrame.x, (int)pointOnFrame.y, 1, 1 };
gtk_popover_set_pointing_to(popOver, &rect);
gtk_popover_popup(popOver);

How can I properly reparent the popover so that it appears on the desired parent widget?

Don’t do this.

Use a different popover for every UI element that can have a menu; at most, you can share the menu model across multiple popovers.

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