I am having a GtkStack with one page defined from a XML file. That particular stack and stack page works.
Later on (in a .so added with g_module_open), I want to add pages to that GtkStack.
Obviously, I don’t know what I am doing. Stack pages are not derived from GtkWidget so how to do this? I have tried also to put a GtkBox on top of the GtkStack. The removes the error but no pages are added to the stack.
Still doesn’t work but the widget that the stack page refers to seems to change one of the widgets in the stack that “preferences” refers to. I was (naively, I guess) expecting that I would get another page added to the stack “preferences”, not messing up widgets that I have on the other stack pages.
No, I have defined a stack and a page in the main program (as part of a menu). The main g_module_open:s a .so with its own UI that wants to add another page to that stack (the main has its preferences page and the linked .so wants to add its own preferences page to the same stack which is part of a menu).
The solution to my problem appears to be to just define a widget, I my case a Box and do all the GtkStackPage-related stuff in the code.
last_visible = gtk_stack_get_visible_child (preferences); /* this is just to restore current view */
my_preferences = GTK_BOX (gtk_builder_get_object (builder, "my-pref"));
GtkStackPage* my_page = gtk_stack_add_child(preferences, GTK_WIDGET (my_preferences));
gtk_stack_page_set_title(my_page, "My Preferences");
If I don’t save last_visible, then when “my-pref” is removed, the “preferences” GtkStack shows nothing.
Maybe this helps somebody because there is not so much written about this that I could find.
Sorry for that. When I don’t get things to work, I go through a bunch of variations of how to interpret the API. This must have been a leftover from that.
The thing that solved it for me was realizing that gtk_stack_add_child returns GtkStackPage*.