0

I have a Gtk Listbox to which I'm adding a large number of items (basically text labels). I've put the ListBox inside a ScrolledWindow but if I add too many items then the height of each item is reduced until the text on the label is no longer readable.

How can I prevent the ListBox items from being reduced in height as I add more of them?

The code I'm using to create the ListBox and add the items looks like this:

# Add the listbox
self.test_list_window = Gtk.ScrolledWindow();
self.test_list = Gtk.ListBox()
self.test_list.connect("row_activated", some_method)
self.test_list_window.add(self.test_list)

The adding of the items is done with this method (each ListBox item has a LHS and RHS label). I thought that the set_size_request would add a minimum size to the ListBox entries but it does not appear to do so (also setting a specific height in pixels feels like the wrong answer I just want to prevent the rows from shrinking).

def add_list_box_entry(self, lhs, rhs, lbox, set_min_size=False):
        box = Gtk.Box()
        if set_min_size:
            box.set_size_request(10, 10)
        box.pack_start(Gtk.Label(label=lhs, xalign=0), True, True, 1)
        lab = Gtk.Label(label=f'({rhs})')
        lab.set_halign(0.95)
        box.pack_start(lab,False, True, 5)
        lbox.add(box)
Carcophan
  • 1,508
  • 2
  • 18
  • 38

1 Answers1

0

To resolve this behavior you need to call show_all() on the Listbox after adding the items.

If you don't there is a vertically tiny entry in the Listbox for each item you added. This can be clicked on but that doesn't display the widgets it contains and so can give the impression that the items have been scaled down from their normal height.

Carcophan
  • 1,508
  • 2
  • 18
  • 38