如何获得可见的项目边界框?
我有一个场景,其中包含许多 qgraphicSitem
项目(大约25000个项目),当我隐藏无用的项目时,我如何获得所有可见的项目bounding-box,以便我可以使用 fitinview 确保仅在视图中心中的可见项目。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有一个场景,其中包含许多 qgraphicSitem
项目(大约25000个项目),当我隐藏无用的项目时,我如何获得所有可见的项目bounding-box,以便我可以使用 fitinview 确保仅在视图中心中的可见项目。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
我认为没有任何功能可以限制仅获得可见项目的矩形。我将使用蛮力,对所有可见项目进行迭代并计算总边界矩形。例如,查看
qgraphicsScene :: itemboundingRect()
的实现。此处https://code.woboq.org/qt5/qtbase/src/widgets/graphicsview/qgraphicsscene.cpp.html#_ZNK14QGraphicsScene17itemsBoundingRectEv and add visibility check to it 。如果由于大量的看不见的物品,这种蛮力的性能并不令人满意,那么您可能应该在某处保留一些仅可见物品的列表,但您需要注意维护并每次显示或hide或hide或添加或添加或删除时进行更新现场的任何东西。然后,您可以更快地迭代如此较小的项目列表。但是,除非蛮力方法的性能真的很差,否则我不会这样。
I do not think there is any function for bounding getting rect of only visible items. I would use brute force, iterating over all visible items and calculating the total bounding rect. For example have a look at the implementation of
QGraphicsScene::itemsBoundingRect()
here https://code.woboq.org/qt5/qtbase/src/widgets/graphicsview/qgraphicsscene.cpp.html#_ZNK14QGraphicsScene17itemsBoundingRectEv and add visibility check to it.If this brute force performance is not satisfactory due to large number of invisible items, then you should probably keep some list of only visible items somewhere but you need to take the care to maintain it and update it everytime you show or hide or add or remove anything to the scene. Then you could iterate over such smaller list of items much faster. But I would not go this way unless the brute force method performance is really bad.