QGraphicsView绘制巨大网格-如何优化?
我需要为我的应用程序绘制一个大网格(例如 100 行,1000 列)。我正在使用带有 opengl 视口集的 QGraphicsView (不会提高性能太多)。
该应用程序响应速度相当快,但我想知道我做得是否正确。
基本上我有一个继承 QGraphicsItem 的 GridItem,并且我尝试了两件事:
1)构造函数创建了数千个 QGraphicsRectItem,并将其(GridItem)作为(QGraphicsItem *)父级传递。我已经正确实现了boundingRect()成员(我相信)。
2)构造函数以相同的方式创建许多QGraphicsLineItem。
在这两种情况下,GridItem 的 Paint 方法不执行任何操作,因为子元素的绘制是由 Qt 自动处理的。
选项 1) 的速度大约是选项 2) 的三倍。我的结论是,延伸到视口之外的大线没有得到太多优化,并且不必要地重绘了太多对象。您认为这是正确的解释吗?
这让我怀疑我是否正确地处理了这个问题。你会如何绘制一个非常大的网格?
在该网格的顶部,我还有另一层可点击、可拖动等的正方形。
提前致谢!
问候,
djfm
I need to draw a big grid for my app (like 100 rows, 1000 columns). I am using a QGraphicsView with opengl viewport set (doesn't improve performance much).
The app is reasonably responsive, but I'd like to know if I'im doing things right.
Basically I have a GridItem that inherits QGraphicsItem and I have tried two things :
1) The constructor creates thousands of QGraphicsRectItem's passing this (the GridItem) as the (QGraphicsItem*) parent. I have implemented the boundingRect() member correctly (I believe).
2) The constructor creates lots of QGraphicsLineItem's in the same manner.
In both cases, the paint method of GridItem does nothing as the drawing of the child elements is handled automagically by Qt.
Option 1) is about three times faster then option 2). My conclusion is that big lines that extend beyond the viewport are not optimized much and too many objects are redrawn unnecessarily. Do you think this is the correct explanation?
This made me wonder whether I was handling the problem correctly at all. How would you go about drawing a very big grid?
On top of that grid, I have another layer of squares that are clickable, draggable, etc.
Thanks in advance!
Regards,
djfm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论