Remove child from paned in gtk4

Hi all,

How can I remove both children from a GtkPaned in Gtk4 without destroying them (to be able to move them into another container)? In Gtk3 I used gtk_container_remove(…), but that method doesn’t exist anymore in Gtk4.


The documentation does not accurately state that the argument is nullable, but gtk_paned_set_start_child() and gtk_paned_set_end_child() can take NULL, and that will remove the child.

1 Like


I tried it, but I receive a ton of

(test_gtk4:18277): Gtk-CRITICAL **: 00:22:19.677: gtk_widget_get_parent: assertion ‘GTK_IS_WIDGET (widget)’ failed

as soon as I set one of the children to NULL (and with “a ton” I mean that the message repeats ad finitum).

If you plan on reparenting the widget, you’ll want a call to gtk_paned_get_start_child() first (followed by a g_object_ref() if not using a language like JS). Otherwise, you’re probably dropping the last reference to the child widget when you remove it from the GtkPaned

There’s only a handful of calls to gtk_widget_get_parent() in gtkpaned.c, so if on the off-chance that there is a bug in GtkPaned a backtrace to that critical would be helpful.

I keep outside the paned my own reference to the element that I’m removing, so it doesn’t seem like I’m dropping the last reference. Also, the “warning loop” happens inside the call to gtk_paned_set_start_child() (it never returns). I’ll prepare a very simple code example, give me some minutes.

Well, this is odd… I did a test code, and it does work fine, so the bug seems to be in my original code (or maybe it is something more convoluted…)

Give me some extra time…

Ok… The problem seems to be in gtk_paned_set_focus_child(): it enters in an infinite loop for some reason.


I’ll try to reproduce this bug, and also send a patch.

Ok, I think that I found how to fix it: the loop must stop if w is NULL. That’s the case that isn’t being taken into account.

Ok, I’ve been able to reproduce the bug, and sent a patch for it:

1 Like

Nice one, another bug squashed :slight_smile:

1 Like

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