Incorrect widget height when GtkScrolledWindow is nested in GtkExpander?

Hello everybody,

in my application I have a big widget inside of GtkScrolledWindow, which is added to GtkExpander. For some reason such GtkExpander does not take full available height in expanded state. If I add GtkScrolledWindow to dialog, it fills all available space, but if I insert GtkScrolledWindow between GtkScrolledWindow and dialog, most of the dialog height is left unused.

GTK library version is 3.24.18.

Could this be a bug or am I doing something wrong?
Minimal reproduction code (I expect red scrolled area to fill all dialog height):

// gcc `pkg-config --cflags gtk+-3.0` -o test test.c `pkg-config --libs gtk+-3.0`
#include <gtk/gtk.h>

int main(int argc, char *argv[]) {
  GtkWidget *scrolledWindow, *window, *expander, *widget;
  GtkStyleContext *context;
  GtkCssProvider *provider;
  gtk_init(&argc, &argv);

  widget = gtk_label_new("Test");
  context = gtk_widget_get_style_context(widget);
  provider = gtk_css_provider_new();
                                  "* { background-color: red; }", -1, NULL);
  gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(provider),

  gtk_widget_set_size_request(widget, 100, 1200);
  scrolledWindow = gtk_scrolled_window_new(0, 0);
  gtk_container_add(GTK_CONTAINER(scrolledWindow), widget);
  expander = gtk_expander_new("Show");
  gtk_container_add(GTK_CONTAINER(expander), scrolledWindow);
  gtk_expander_set_expanded(GTK_EXPANDER(expander), TRUE);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "Window");
  gtk_window_set_default_size(GTK_WINDOW(window), 600, 400);
  gtk_container_add(GTK_CONTAINER(window), expander);

I managed to fix my issue by enabling natural height propagation by calling gtk_scrolled_window_set_propagate_natural_height(widget, TRUE) on GtkScrolledWindow.

Like so:

gtk_scrolled_window_set_propagate_natural_height(GTK_SCROLLED_WINDOW(scrolledWindow), TRUE);

Hopefully this will be useful to somebody else.

1 Like

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