Issues with scrollable ListBox in Notebook
Hey, thanks for all your great work on GTK! I'm the developer of this little app, which uses a ListBox in a ScrolledWindow in a Notebook to display a list of items. While trying to update the GNOME runtime of the Flatpak version to 42, I ran into two issues with this setup:
-
Changing the selected row affects the horizontal adjustment of the ScrolledWindow. It basically alternates between scrolling all the way to the left and all the way to the right.
-
Changing the notebook page changes the selected row (from the current one to the next one) of the respective ListBox. This also happens if multiple rows were selected before.
In combination, these issues make ListBoxes in Notebooks almost unusable for me. (I also ran this issue, but that's less critical.)
Here is short video:
Screencast_03-28-2022_12_04_49_PM
I'm pretty much a novice when it comes to GTK, so I'm not sure if I'm doing anything wrong. This is the code of the widget in the video:
#!/usr/bin/env python3
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, GObject, Gio
class Row(Gtk.ListBoxRow):
def __init__(self, number):
super().__init__()
self.set_activatable(False)
label_1 = Gtk.Label(xalign=0)
label_1.set_text(f" Row {number}")
label_2 = Gtk.Label(xalign=0)
label_2.set_text(f" A l{100*'o'}ng string")
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box.set_margin_top(5)
box.set_margin_bottom(5)
box.append(label_1)
box.append(label_2)
self.set_child(box)
class PageHeader(Gtk.Box):
def __init__(self, number):
super().__init__()
self.set_orientation(Gtk.Orientation.HORIZONTAL)
title_label = Gtk.Label(label=f"Page {number}")
close_button = Gtk.Button.new_from_icon_name("window-close-symbolic")
close_button.set_has_frame(False)
self.append(title_label)
self.append(close_button)
def on_activate(app):
window = Gtk.ApplicationWindow(application=app)
window.set_default_size(600, 400)
notebook = Gtk.Notebook()
window.set_child(notebook)
for n in range(2):
listbox = Gtk.ListBox()
listbox.set_show_separators(True)
listbox.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
listbox.set_activate_on_single_click(False)
for i in range(20):
listbox.append(Row(i))
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_vexpand(True)
scrolled_window.set_child(listbox)
notebook.append_page(scrolled_window, PageHeader(n))
window.show()
app = Gtk.Application()
app.connect("activate", on_activate)
app.run()
GTK version: 4.6.2 (GNOME 42 flatpak runtime), host system: Fedora 35