Gtk4: Scrolling down ListView items get skipped and scrolling up get stuck in a loop range

I am displaying a GtkStringList of 1000 strings in a GtkListView within a ScrolledWindow. When i scroll down and reach around 400th to 500th item, it skips ahead and start to display around the 700th item and beyond.

When i reach the end ie. 1000th item and start scrolling up to the 1st item, when it reaches around 500th item it loops back to around 900th item and keeps looping back when scrolling up to the 500th item and cannot scroll back to the 1st item.

In the terminal i get several of these warnings while scrolling: **(listview:12605): Gtk-WARNING **: 05:00:28.634: GtkListView failed to scroll to given position. Ignoring...**

I have tested it on two different machines one with gtk4.2.1 and the other with gtk4.2.0 and both produce the same anomaly. I also tried with ColumnView and got the same scrolling problem.

Note: By scrolling i mean using the mouse wheel or 2 fingers scrolling with touchpad and NOT dragging the scrollbar with the mouse. When dragging the scrollbar with the mouse i don’t get these problems nor the warnings messages.

Here is the code : -----------------------------------------

#include <gtk/gtk.h>

static void
setup_label (GtkSignalListItemFactory *factory,
             GObject                  *listitem)
{
  GtkWidget *label;
  label = gtk_label_new ("");
  gtk_list_item_set_child (GTK_LIST_ITEM (listitem), label);
}

static void
bind_label (GtkSignalListItemFactory *factory,
            GObject                  *listitem)
{
  GtkWidget *label;
  GObject *item;

  label = gtk_list_item_get_child (GTK_LIST_ITEM (listitem));
  item = gtk_list_item_get_item (GTK_LIST_ITEM (listitem));

  gtk_label_set_label (GTK_LABEL (label), 
   gtk_string_object_get_string(GTK_STRING_OBJECT(item))
  );
}

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window, *sw, *listview;
  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);

  sw = gtk_scrolled_window_new ();
  
  GtkStringList* strlist = gtk_string_list_new(NULL);
  for (int index=1; index<=1000; ++index){
    char str[10];
    sprintf(str, "%d", index);
    gtk_string_list_append(strlist, str);
  }
  
  GtkListItemFactory *factory = gtk_signal_list_item_factory_new();
  g_signal_connect (factory, "setup", G_CALLBACK(setup_label), NULL);
  g_signal_connect (factory, "bind", G_CALLBACK(bind_label), NULL);
  
  listview = gtk_list_view_new(
    GTK_SELECTION_MODEL(gtk_no_selection_new(G_LIST_MODEL(strlist))),
    factory
    );

  gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
  gtk_window_set_child (GTK_WINDOW (window), sw);
  gtk_widget_show (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

Yes, this is a known issue. A solution is being worked on.

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