在 HPaned 问题中调整 gtk TreeView 的大小

发布于 2024-10-13 11:51:37 字数 1036 浏览 1 评论 0原文

我在 hpaned 的左侧有一个树视图,但是当我尝试将栏移动到左侧以使树视图小于其自动大小而不是调整树视图大小时,它会将整个程序窗口向右展开。关于如何解决这个问题有什么想法吗?

源的相关部分如下:

对于 hpaned。

    self.vpan = gtk.VPaned()
    self.hpan = gtk.HPaned()
    self.vpan.show()
    self.hpan.show()

    self.vBox1.pack_end(self.hpan, True, True, 0)
    self.hpan.pack2(self.vpan,True, True)

对于树视图。

    self.ftree = gtk.TreeStore(str,str,str)
    self.treefill(None, os.path.abspath(os.path.dirname(__file__)))

    self.tree = gtk.TreeView(self.ftree)
    self.tvcolumn = gtk.TreeViewColumn('Project')
    self.tree.append_column(self.tvcolumn)
    self.cellpb = gtk.CellRendererPixbuf()
    self.celltxt = gtk.CellRendererText()

    self.tvcolumn.pack_start(self.cellpb,False)
    self.tvcolumn.pack_start(self.celltxt,True)

    self.tvcolumn.set_attributes(self.cellpb, stock_id=0)
    self.tvcolumn.set_attributes(self.celltxt, text=1)
    self.tvcolumn.set_resizable(True)

    self.hpan.pack1(self.tree,True,True)
    self.tree.show()

I have a treeview in the left side of an hpaned but when I try to move the bar to the left to make the treeview smaller than its automatic size instead of resizing the treeview it expands the entire program window to the right. Any ideas on how to fix this?

The relevant portions of the source are the following:

For the hpaned.

    self.vpan = gtk.VPaned()
    self.hpan = gtk.HPaned()
    self.vpan.show()
    self.hpan.show()

    self.vBox1.pack_end(self.hpan, True, True, 0)
    self.hpan.pack2(self.vpan,True, True)

And for the tree View.

    self.ftree = gtk.TreeStore(str,str,str)
    self.treefill(None, os.path.abspath(os.path.dirname(__file__)))

    self.tree = gtk.TreeView(self.ftree)
    self.tvcolumn = gtk.TreeViewColumn('Project')
    self.tree.append_column(self.tvcolumn)
    self.cellpb = gtk.CellRendererPixbuf()
    self.celltxt = gtk.CellRendererText()

    self.tvcolumn.pack_start(self.cellpb,False)
    self.tvcolumn.pack_start(self.celltxt,True)

    self.tvcolumn.set_attributes(self.cellpb, stock_id=0)
    self.tvcolumn.set_attributes(self.celltxt, text=1)
    self.tvcolumn.set_resizable(True)

    self.hpan.pack1(self.tree,True,True)
    self.tree.show()

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

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

发布评论

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

评论(1

物价感观 2024-10-20 11:51:37

我正要回答这个问题,然后我发现我的答案是用户答案的​​重复。但是,由于他还没有发布他的决议作为答案,所以我无论如何都会发布。 (如果他没有弄清楚的话,我会发布以下内容。)

“扩展”和“填充”似乎会导致此框中的各个对象之间的空间争夺(因为我假设您的所有对象我以前也有这个习惯,但是没问题。)在PyGTK文档中,“Expand”被定义为

如果要给孩子分配额外的空间给盒子,则为真。额外的
空间将在使用该空间的所有子盒子之间平均分配
选项。

并将“填充”为:

如果扩展选项给子级的空间实际上是
分配给孩子,而不是仅仅填充它。这个参数没有
Expand 设置为 False 时的效果。孩子总是被分配完整的
gtk.HBox 的高度和 gtk.VBox 的全宽度。这个选项
影响其他维度。

所以,从本质上讲,盒子给所有东西都提供了相同的空间……你给一个东西更多的空间,它给另一个东西更多的空间,所有的物体都接受了它并变得更大。然后窗口必须扩展以进行补偿。

要解决此问题,请将这些选项中的一个或两个设置为“False”。将“Expand”设置为“False”也会关闭“Fill”,但只有将“Fill”设置为“False”才会导致框为“Fill-False”对象提供额外的空间作为填充。

I was going to answer this question, and then I realized that my answer was a repeat of the user's answer. But, as he hasn't posted his resolution as an answer, I will anyway. (Below is what I would have posted if he hadn't figured it out.)

Expand and Fill seem to be causing a bit of a fight for space between the various objects in this box (as I'm assuming that all of your objects do this. I used to have the habit, too, but no problem.) In the PyGTK documentation, "Expand" is defined as

True if child is to be given extra space allocated to box. The extra
space will be divided evenly between all children of box that use this
option.

and "Fill" as:

True if space given to child by the expand option is actually
allocated to child, rather than just padding it. This parameter has no
effect if expand is set to False. A child is always allocated the full
height of a gtk.HBox and the full width of a gtk.VBox. This option
affects the other dimension.

So, essentially, the box is giving everything the same space...you give more to one, it gives it to the other, and the objects all take it and get bigger. The window then has to expand to compensate.

To fix this, set one or both of those options to "False". Setting "Expand" to "False" will also shut off "Fill", but only setting "Fill" to "False" will cause the box to give the extra space to "Fill-False" objects as padding instead.

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