Preparing for GtkBox in GTK 4

The recommendations for preparing an app for GTK 4 include Stop using GtkBox padding, fill and expand child properties, with suggestions for how to replace the expand, fill, and padding properties. But not clear is how to stop using those properties in GTK 3 without changing the app’s appearance. Should we continue to use gtk_box_pack_{start,end} with the (inactive) values FALSE, FALSE, 0? Or just use gtk_container_add()? Either way, the effort to port to a GTK 4 environment would be quite simple.

1 Like

HI @PeterB,
I am also wrestling with this problem, in GTK 3.98.4. Be careful, in GTK 4 there is no more gtk_box_pack_start():

I have begun trying things with gtk_widget_set_vexpand():

But I am waiting with you for the official GTK team answer!

Note also that in GTK 4, there will be no more gtk_container_add(). At the time of switch, you will have to replace it with functions such as gtk_window_set_child() , gtk_box_append , gtk_scrolled_window_set_child , gtk_info_bar_add_child , etc.

I think that gtk_box_append () and gtk_box_preapend () together with GtkWidget *align/*expand/*expand-set properties should be used in GTK4, but I am not 100% sure.


What I’m finding is that if I set the GtkWidget properties and then gtk_box_pack_ with expand and fill both FALSE, some widgets do not actually expand (e.g. GtkNotebook). OTOH if I use gtk_container_add, they expand as requested. Perhaps the recommendation should be to stop using gtk_box_pack_{start,end} altogether.

  1. Make the child.
  2. Put it in a box.
  3. Set the child’s properties.
  4. Reset the box’s properties if needed.

In GTK3, both steps 2 and 3 set child properties. In GTK4, only step 3 will do it.

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