0

In my GTK3 window I have a Treeview with many items, so I have make it scrollable. I'm using a Scrolledwindow for that:

self.codes = Gtk.Treeview()
codeswindow = Gtk.ScrolledWindow()
codeswindow.add_with_viewport(self.codes)
codeswindow.show()

When running the application and selecting an item ("selection_changed" event) the Treeview will jump to the top, so the selected item will be out of sight. The same happens when double clicking an item for editing it. After selecting an item I then have to scroll down to the selected item.

How do I prevent this?

Maybe related: When selecting items using Arrow up or Arrow down the window is not scrolling along.

chrwahl
  • 8,675
  • 2
  • 20
  • 30
  • 1
    Not sure if this solves your problem, but TreeViews can scroll natively, without a Viewport. You should change `add_with_viewport` to `add`. – Aran-Fey Mar 09 '18 at 11:00
  • Thanks @Aran-Fey. That actually solved the problem. I will create an answer to my question then. – chrwahl Mar 09 '18 at 11:26

1 Answers1

1

Like suggested in the comment by @Aran-Fey Treeview can scroll natively and quote from documentation:

If a child has native scrolling, use gtk_container_add() instead of this function

and by the way:

gtk_scrolled_window_add_with_viewport has been deprecated since version 3.8 and should not be used in newly-written code.

Replacing add_with_viewport with add solves the problem:

self.codes = Gtk.Treeview()
codeswindow = Gtk.ScrolledWindow()
codeswindow.add(self.codes)
chrwahl
  • 8,675
  • 2
  • 20
  • 30