如何使 IconView 中的图标均匀分布?
我有一个 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.
This is what I'd like to see (of course, with the gaps actually evenly spaced, unlike my poor MS Paint job).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们在 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.
是的,看起来很胖之后,你似乎需要自己做这件事。关于信号,我会检查 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.
使用事件 size_allocate。
我定义了我的班级:
然后我修改了工作列的数量
似乎对我有用
Use the event size_allocate.
I defined my class :
Then I modify the number of working columns
Seems working for me