开发者

Add gtk.TreeView columns to a size group

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开发者_如何学C is not a widget... how can I do this?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜