QT如何画50万条线?
我需要在 QGraphicsView 等某些区域绘制很多(大约 500000 条)小线。 我尝试使用 QPainterPath 和 QGraphicsScene,但是使用 lineTo() 添加 500000 行到 QPainterPath 需要超过 500 MB 的内存,并且我的应用程序被我的内核杀死。
有没有办法可以在QT中画这么多的线?
I need to draw a lot of (about 500000) little lines in some area like QGraphicsView.
I tried to use QPainterPath and QGraphicsScene, but adding 500000 lines to QPainterPath with lineTo() takes more than 500 mb of memory and my app is killed by my kernel.
Is there a way I can draw such amount of lines in QT?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QGraphicsLineItem
可能比QPainterPath
具有更低的开销代码>.但增加一百万个就会抵消收益。假设您将所有线条视为一项,因为您要将线条添加到 QPainterPath,创建自定义
QGraphicsItem
和paint()
自己排队将是最快的方法。它还将避免管理路径和线路结构的所有内存负担。QGraphicsLineItem
probably has lower overhead thanQPainterPath
. But adding half of a million of them will negate the gain.Assuming that you are treating all the lines as one item since you are adding lines to a
QPainterPath
, creating a customQGraphicsItem
andpaint()
the lines yourself will be the fastest way. It will also avoid all the memory burden of managing path and line structures.