如何使 IconView 中的图标均匀分布?

发布于 2024-12-13 03:41:53 字数 510 浏览 0 评论 0原文

我有一个 gtk.IconView ,里面有几个图标。有时我会调整窗口大小以查看更多图标。当我这样做时,生成的额外空间并未均匀分布在所有列之间。相反,所有内容都会放在右侧,直到有足够的空间容纳新列。

我在文档中没有看到任何可以让我做的事情自动执行此操作。我是否需要检查调整大小信号,然后手动设置列间距和行间距?如果是这样,我应该使用哪个调整大小信号。

这是我的意思的图片。我已将多余的空间标记为红色。

在此处输入图像描述

这就是我想看到的(当然,间隙实际上是均匀分布的,不像我的糟糕的 MS Paint 工作)。

在此处输入图像描述

I have a gtk.IconView with several icons in it. Sometimes I will resize the window to see more icons. When I do this, the extra space generated isn't distributed evenly between all the columns. Instead, it all gets put on the right until there's enough space for a new column.

I'm not seeing anything in the documentation that would let me do this automatically. Do I need to check for resize signals and then manually set the column and row spacings? If so, which resize signal do I use.

Here's a picture of what I mean. I've marked the extra space in red.

enter image description here

This is what I'd like to see (of course, with the gaps actually evenly spaced, unlike my poor MS Paint job).

enter image description here

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

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

发布评论

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

评论(3

看春风乍起 2024-12-20 03:41:53

我们在 Ubuntu Accomplishments Viewer 中遇到了这个问题,当我们设法解决它时,我将介绍我们的解决方案。

诀窍是将 GtkIconView 放入 GtkScrolledWindow 中,并将其 hscrollbar_policy 设置为“always”。然后,必须使用检查调整大小信号,以便在用户调整窗口大小时做出反应(请注意,必须检查大小是否已更改,因为当窗口被拖动时也会发出该信号)。当大小发生变化时,必须清除并重新创建 GtkIconView 使用的模型,因为这会触发 GtkIconView 正确地重新分配新获得的空间(或缩小)。 而且,结果水平滚动条将永远不会被看到,因为 GtkIconView 使用的空间与 GtkScrolledWindow 使用的空间完全相同。

We have encountered that problem in Ubuntu Accomplishments Viewer, and as we managed to solve it, I'll present our solution.

The trick is to place the GtkIconView in a GtkScrolledWindow, and set it's hscrollbar_policy to "always". Then, a check-resize signal has to be used, to react when the user resizes the window (note that it must be checked if the size has changed, for the signal is emitted also when e.g. the window is dragged around). When the size changes, the model used by GtkIconView has to be cleared and recreated, as this triggers GtkIconView properly reallocating the newly gained space (or shrinking). Also, as the result the horizontal scrollbar will never be seen, as the GtkIconView uses exactly that much space as the GtkScrolledWindow uses.

森林散布 2024-12-20 03:41:53

是的,看起来很胖之后,你似乎需要自己做这件事。关于信号,我会检查 GtkContainer::check-resize

Yeap, it seems after a very fat look that you will need to do that on your own. And regardeing the signal, I'd check for GtkContainer::check-resize.

怪我闹别瞎闹 2024-12-20 03:41:53

使用事件 size_allocate。

我定义了我的班级:

class toto(Gtk.IconView):
    def __init__(self):
        super(toto,self).__init__()
        self.connect("size_allocate",self.resize)
        self.set_columns(4)

然后我修改了工作列的数量

def resize(self,_iv,_rect):
    print("X",rect.x)
    print("Y",rect.y)
    print("W",rect.width)
    print("H",rect.height)
    # calculate number of columns, let's say 3
    _cols=3
    self.set_columns(_cols)

似乎对我有用

Use the event size_allocate.

I defined my class :

class toto(Gtk.IconView):
    def __init__(self):
        super(toto,self).__init__()
        self.connect("size_allocate",self.resize)
        self.set_columns(4)

Then I modify the number of working columns

def resize(self,_iv,_rect):
    print("X",rect.x)
    print("Y",rect.y)
    print("W",rect.width)
    print("H",rect.height)
    # calculate number of columns, let's say 3
    _cols=3
    self.set_columns(_cols)

Seems working for me

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