You cannot add a GtkPopover to any random widget: you need to create a custom widget class that holds both the popover and the widget that should display it.
If you want to have a button with a popover, use GtkMenuButton.
GMenu \*menu = g_menu_new();
// Insert custom placeholder at position 0 (top)
GMenuItem \*custom_item1 = g_menu_item_new("Custom Area", NULL);
g_menu_item_set_attribute(custom_item1, "custom", "s", "custom-1");
g_menu_insert_item(menu, 0, custom_item1);
g_object_unref(custom_item1);
// Create menu items with labels
GMenuItem \*item1 = g_menu_item_new("Item 1", NULL);
// Create themed icons
GIcon \*icon1 = g_file_icon_new(g_file_new_for_path("/home/user/Downloads/file.png"));
// Attach icons to the items
g_menu_item_set_icon(item1, icon1);
// Append items into the menu
g_menu_append_item(menu, item1);
// Cleanup
g_object_unref(item1);
g_object_unref(icon1);
// Create popover from model
GtkWidget \*popover = gtk_popover_menu_new_from_model(G_MENU_MODEL(menu));
gtk_widget_set_parent(popover, button);
GtkWidget \*box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
GtkWidget \*image = gtk_image_new_from_file("/home/user/Downloads/file.png");
GtkWidget \*label = gtk_label_new("Custom Image");
gtk_box_append(GTK_BOX(box), image);
gtk_box_append(GTK_BOX(box), label);
gtk_widget_set_visible(box, TRUE);
gtk_popover_menu_add_child(GTK_POPOVER_MENU(popover), box, "custom-1");
// Show the popover
gtk_widget_set_visible(popover, TRUE);
}
Background: I was trying to support icon in Eclipse SWT.. currently in SWT for popover menu consumption icon support is missing.. One idea was to support it through custom widget(Box+Image). I was thinking custom widget can be supported on Item.. But it seems custom widget is a new menu item itself..