0

I want to stack two treeviews on each other and have the columns be aligned. I figured the way to do this would be to use a gtk.SizeGroup somehow. However, gtk.TreeViewColumn is not a widget... how can I do this?

gpoo
  • 8,408
  • 3
  • 38
  • 53
Claudiu
  • 224,032
  • 165
  • 485
  • 680
  • i've tried setting custom widgets for the headers, and adding those to a size group, but that did not work. also didn't work is inspecting the widgets in a treeview with forall and attempting to sizegroup the corresponding ones. – Claudiu Oct 22 '10 at 16:50

2 Answers2

1

I have two suggestions:

  1. Look at how gtk.SizeGroup is implemented and see if you can write your own TreeViewColumnSizeGroup.
  2. Connect to notify::width of each column and in the callback set the width of the corresponding column in the other treeview.
ptomato
  • 56,175
  • 13
  • 112
  • 165
  • the problem seems to be that TreeViewColumn is just an Object which is used to help the treeview draw the columns, but it's not the actual widget it uses. so it seems to have no `notify` events, so I'm not sure how I'd do #1 either – Claudiu Oct 22 '10 at 14:34
  • ohh got it now.. didn't understand how notify events worked ([this answer](http://stackoverflow.com/questions/3999146/detect-when-column-in-gtk-treeview-is-resized/3999311#3999311) cleared it up) – Claudiu Oct 22 '10 at 17:41
  • slight problem with #2: i can't shrink the widget now, because one of them has fixed width, causing the window to remain at the size it is.. – Claudiu Oct 22 '10 at 18:47
  • another problem is that if the 'slave' view needs a larger column, it will get clipped instead of expanding both. i'll need to think of a better solution – Claudiu Oct 22 '10 at 19:00
0

UPDATE: This is the final code that worked. In a loop I'm building both view columns at the same time, so this line is sufficient:

col1.connect("notify::width", lambda col1,_,col2:col2.set_fixed_width(
    col1.get_width()), col2)

I think the reason there is no "column widget" is that the main area is just a gtk.gdk.Drawable where each of the cell renderers draw their stuff. However, each column has headers that are widgets, so we can use those to do what we want.

Pick one view to be the 'main' one, and set the other to have gtk.TREE_VIEW_COLUMN_FIXED sizing. Use .forall() to go through the internal child widgets of the 'main' view. These will be gtk.Buttons representing the column headers. Connect to their size-allocate event. On that event handler, get the requested width, and .set_fixed_width of the corresponding column on the slave view.

    self._svcols = []
    def sizealloc(wid, alloc):
        ci = self._svcols.index(wid)
        cl = self.slaveView.get_column(ci)
        cl.set_fixed_width(alloc.width)

    def resizes(child):
        child.connect('size-allocate', sizealloc)
        self._svcols.append(child)

    self.mainView.forall(resizes)

This works even if the column headers are not being shown.

Claudiu
  • 224,032
  • 165
  • 485
  • 680