可排序QHBoxLayout [英] Sortable QHBoxLayout

查看:140
本文介绍了可排序QHBoxLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Qt来创建一个可排序的条形图形小部件。

I'm using Qt to create a sortable bar graph-like widget. The widget is laid out with a QHBoxLayout for each bar in the graph (which are also widgets).

当用户更改排序参数时,我的控制器会清除布局,排序它,并按顺序对每个项目调用addWidget。我面临的问题是,这个列表是相当大(1000+小部件),并且Qt正在爬行,当尝试布局这许多元素。

When the user changes the sorting parameters, my controller clears the layout, sorts it, and calls addWidget on every item in order. The problem I'm facing is that this list is quite large (1000+ widgets), and Qt is crawling when attempting to layout that many elements.

每次调用addWidget时,Qt会重新计算QHBoxLayout中每个项的位置,然后更新。这是一个问题,因为它对每个LayoutItem执行大量不必要的计算之前,我添加一个。对于我投入的1000个测试项目,解析需要大约30秒,这显然是太长了。

I've found out that each time addWidget is called, Qt will recalculate the location of every item in the QHBoxLayout and then update. This is a problem, as it performs a lot of unnecessary calculations on each LayoutItem before the one I am adding. For 1000 test items that I'm putting in, resorting takes around 30 seconds, which is obviously far too long.

有更好的布局类型要使用,有更快的方法来添加排序的小部件集合到布局?

Is there a better Layout type to use, or is there a faster way to add a collection of sorted widgets to a layout?

编辑:
显然,我一直在使用的问题不是与Qt再次布置每个项目,但所有的父母和shenanigans的内部在幕后我设置了一个测试项目添加1000个按钮到布局,每次打印一个计数器。数字几乎瞬间打印出来,虽然它花了相同的〜30秒让Qt伸直自己。我认为问题不存在只有与QHBoxLayout,但与Qt的布局系统一般。看起来我会手动定位小部件和绕过一个QLayout完全。感谢所有提供输入的人。

Apparently, the issue I've been having isn't with Qt laying out each item again, but the internals of all the parenting and shenanigans that go on behind the scenes I set up a test project to add 1000 buttons to a layout, printing out a counter each time. The numbers printed out almost instantaneously, though it took that same ~30 seconds for Qt to straighten itself out. I think the problem doesn't exist only with QHBoxLayout, but with Qt's layout system in general. Looks like I'll be manually positioning widgets and bypassing a QLayout altogether. Thanks to everyone who gave their input.

推荐答案

documenation void QLayout :: setEnabled(bool enable)


如果enable为true,则启用此布局,否则禁用它。

启用的布局可动态调整更改;一个禁用的布局就像
不存在一样。

默认情况下,所有布局都被启用。

Enables this layout if enable is true, otherwise disables it.
An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.
By default all layouts are enabled.

这篇关于可排序QHBoxLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆