确定 TreeView 行的高度

发布于 2024-12-02 01:55:18 字数 274 浏览 2 评论 0原文

我想设置树视图小部件的高度以容纳 N 行,为此我需要确定单个行的高度。

我正在使用下面的代码:

path = Gtk.TreePath().new_first()
height = tree_view.get_cell_area(path, column).height

创建树小部件、填充数据模型并选择第一行后,高度设置为 0。我缺少什么?

PS:当从“row_activated”信号处理程序运行时,相同的代码将返回有效的高度。

I want to set the height of a treeview widget to accommodate N rows, in order to do that I need to identify a single row height.

I am using the code below:

path = Gtk.TreePath().new_first()
height = tree_view.get_cell_area(path, column).height

After creating the tree widget, filling the data model, and selecting the first row, height is set to 0. What I am missing ?

P.S.: The same code will return a valid height when run from a "row_activated" signal handler.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不顾 2024-12-09 01:55:18

大概是这样的:(从gtk站点读取):

“如果path指向当前未显示的路径,则矩形的y和height属性将为0。所有单元格矩形的总和不会覆盖整个树;还有额外的例如,返回的矩形相当于传递给 gtk.CellRenderer.render() 方法的 cell_area。此方法仅在实现树视图时才有效。

您还可以使用以下代码强制在 gtk 中显示待处理的操作:

    ##  force the refresh of the screen
    while gtk.events_pending():
        gtk.main_iteration()

Probably this : (read from the gtk site) :

"If path points to a path not currently displayed, the y and height attributes of the rectangle will be 0. The sum of all cell rects does not cover the entire tree; there are extra pixels in between rows, for example. The returned rectangle is equivalent to the cell_area passed to the gtk.CellRenderer.render() method. This method is only valid if the treeview is realized."

You may also force the display of pending operations in gtk with this code :

    ##  force the refresh of the screen
    while gtk.events_pending():
        gtk.main_iteration()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文