2

I am using a pygtk application and I have added a Treeview inside a ScrolledWindow. Now I want to freeze the first column (fix the column position), so that when scrolling the Treeview horizontally the column position is fixed and still visible (as it's done in excel for the row column).

So how I can freeze the Treeview column in pygtk?

slodeveloper
  • 242
  • 3
  • 21
Siddaram H
  • 1,126
  • 12
  • 17

1 Answers1

0

The closest I've been able to get is a bit of a kludge. I use Perl, not Python, so I'll just describe my technique.

Connect to the treeview's scroll-event signal and watch for direction=left/right (or smooth with get_scroll_deltas() returning non-zero for the X axis). Be sure to return FALSE for vertical scrolling so that remains unaffected. Then show/hide the columns after the fixed one(s) and return TRUE.

For example: when scrolling right, hide column 2, then 3, etc. When scrolling left, show the highest number column that's hidden.

There are a couple drawbacks:

  • It's not as smooth as what you're looking for (columns can't be partially hidden).
  • Doesn't work with the scrollbar, only when tilting the mouse wheel. Not all mice have tiltable wheels.
TheAmigo
  • 1,032
  • 1
  • 10
  • 29
  • When scrolling it from left to right, The complete window inside the scrollbar is moving. How will I know the specific columns got hidden? – Siddaram H Apr 19 '16 at 05:07
  • Since it'd be your callback that's hiding them, you'd have to track which ones you've hidden and then re-show them. – TheAmigo Apr 19 '16 at 12:52
  • There are no explicit callbacks implemented for the treeview to hide the columns but gtk treeview handles it natively. Now I've added an event that emits when scolled the scrollbar horizontally. Now, 1) How I can get the width of a treeview column? 2) Is there anyway I can hide the column partially ? – Siddaram H Apr 28 '16 at 14:15
  • 1) I don't know if there's an easy way (for resizable columns you can call get_fixed_width(), but that probably doesn't work for auto-sized columns). 2) That was one of the drawbacks I mentioned: "columns can't be partially hidden". The closest you can do is change the width... it's going to look goofy and confusing. – TheAmigo Apr 28 '16 at 20:32