且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测gtk.treeview中的列是否调整大小

更新时间:2023-01-27 11:08:03

gtk.TreeViewColumn 不是窗口小部件,所以他们很遗憾没有专门的尺寸变更信号。但是您可以注册一个回调函数,该函数接收宽度更改通知

  def onColWidthChange(col,width):
#请注意,width是一个GParamInt对象,不是整数
...

col.connect(notify :: width,onColWidthChange)

$ b $ p

在这个例子中, col 必须是 gtk.TreeViewColumn 对象。如果你没有在代码中初始化列,你可以使用 gtk.TreeView.get_column 获取这些对象。



如果你只有当treeview改变它的大小时才需要通知,你可以使用它的size-allocate信号。


What signal can I catch to detect when a column changes size in a gtk.TreeView? I can't seem to find it in the docs.

gtk.TreeViewColumns aren't widgets so they unfortunately don't have a dedicated signal for size changes. But you can register a callback function that receives "width" change notifications:

def onColWidthChange(col, width):
    # Note that "width" is a GParamInt object, not an integer
    ...

col.connect("notify::width", onColWidthChange)

In the example, col must be a gtk.TreeViewColumn object. If you don't initialize the columns in code, you can use gtk.TreeView.get_column to get these objects.

If you only need notifications when the treeview changes its size, you can use its "size-allocate" signal instead.