[PyGObject] Gtk.TreeView: compute max rows in visble area

Before filling a Gtk.TreeView with content I want to know how much rows
(of same height) I can put into it before reaching the invisible area
where I have to scroll into. I want to offer my users a TreeView not as
a scrollable list but as a page like view.

I DuckDuckGo'ed around and also read the docu. As I can see there is no
easy way to ask the Gtk.TreeView itself for this information. IMO it
should be possible. So the main question to the core devs is if this is
an acceptable feature request or not?

Currently I see three not so easy and clean ways to workaround the
problem. I would be interested in your opinions about them. Please also
take my other posting about Gtk.TreeView.get_vsible_range() into

1. CellRenderer height
First you have to add one row to the TreeView.
Ask the CellRenderer for its height. Assume the real row height a bit
higher - round about 2 or 4 pixel.
Do Gtk.TreeView.get_visible_rect().
Do visble_rect.height / row_height and you got the number.
Problems: The magic number doesn't work well. As higher the TreeView
becomes (e.g. on a 90° rotated display) there is more empty space at
the end of the view.

2. get_cell_area()
Alternativ to 1. you can compute the height of a row via
Gtk.TreeView.get_cell_area(). But you also have to use a magic number

3. get_visible_range()
Fill the TreeView (more specific its model) step by step with rows.
After each row ask Gtk.TreeView.get_visible_range() and check if the
resulting end_path fits to the last added row or not.
But there might be undocumented problems with that function.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]