2

I'm using Gtk to build an application on Linux using Python 3. I'm trying to use a Gtk.HeaderBar. So far it's been working Ok, but it seems that I can't get it to expand it's child widgets. For example:

Gtk.HeaderBar issue

As you can see above, I've tried putting my Gtk.Entry into the Gtk.HeaderBar, but even with things like Gtk.Entry.set_hexpand(True) it simply refuses to expand. I've even tried putting it inside a Gtk.Box, expanding the Gtk.Box, then adding the Gtk.Entry inside that. Even when I set the Gtk.Entry as a custom title for the Gtk.HeaderBar, this happens:

enter image description here

What's causing this? How can I fix it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Barry Smith
  • 281
  • 1
  • 4
  • 16

2 Answers2

1

Enabling hexpand only says that you want the widget to be allocated all the remaining space; it does not actually resize your widget. You want the halign property set to GTK_ALIGN_FILL (or whatever it's called in Python) in addition to hexpand.

Check the diagrams on this page for a visual explanation.

andlabs
  • 11,290
  • 1
  • 31
  • 52
  • I'd love to say it worked, but it didn't. It's simply refusing to expand either horizontally or vertically, even when using both .set_halign() and .set_hexpand(). It's strange, it works elsewhere in my program. Only the Gtk.HeaderBar doesn't like it. The only thing that seems to work is .set_size_request(), but that doesn't do what I want it to. – Barry Smith Sep 04 '14 at 16:30
  • Well guess what? I'm hitting this bug too now! Yay!!!~~ The joys of knowing what you're talking about (but to be fair, this symptom and this fix usually go together...). – andlabs Sep 06 '14 at 19:42
  • Four years later, same problem. No idea how to make widgets expand in the header bar. – Andreas Raster Apr 11 '18 at 00:23
  • 1
    It appears GTK+ 3.22 has the solution now: [set `hexpand` to `TRUE` for the custom title widget](https://gitlab.gnome.org/GNOME/gtk/commit/0015ebc4a8f269f6888fcacef3e83e3167241d67) (via Christian Hergert) – andlabs Apr 15 '18 at 19:16
1

You can use Box instead of Headerbar with window.set_titlebar method

br.
  • 1,259
  • 1
  • 14
  • 21