gpt4 book ai didi

performance - QGraphicsScene,项目坐标影响性能?

转载 作者:行者123 更新时间:2023-12-03 23:55:24 24 4
gpt4 key购买 nike

使用下面的代码片段,我创建了一个包含 100.000 个矩形的场景。
表现不错; View 响应没有延迟。

QGraphicsScene * scene = new QGraphicsScene;
for (int y = -50000; y < 50000; y++) {
scene->addRect(0, y * 25, 40, 20);
}
...
view->setScene(scene);

现在第二个片段很烂
for (int y = 0; y < 100000; y++) {
scene->addRect(0, y * 25, 40, 20);
}

对于场景元素的第一半, View 延迟响应鼠标和键事件,而对于另一半似乎没问题?!?

前一个场景有sceneRect (x, y, w, h) = (0, -1250000, 40, 2499995)。
后一个场景有sceneRect (x, y, w, h) = (0, 0, 40, 2499995)。

我不知道为什么sceneRect会影响性能,因为BSP索引是基于相对项目坐标的。

我错过了什么吗?我没有在文档中找到任何信息,
加上 Qt 演示 40000 Chips还将元素分布在 (0, 0) 附近,而不解释该选择的原因。
 // Populate scene
int xx = 0;
int nitems = 0;
for (int i = -11000; i < 11000; i += 110) {
++xx;
int yy = 0;
for (int j = -7000; j < 7000; j += 70) {
++yy;
qreal x = (i + 11000) / 22000.0;
qreal y = (j + 7000) / 14000.0;
...

最佳答案

我有一个解决方案给你,但保证不会问我为什么这有效,
因为我真的不知道:-)

QGraphicsScene * scene = new QGraphicsScene;
// Define a fake symetrical scene-rectangle
scene->setSceneRect(0, -(25*100000+20), 40, 2 * (25*100000+20) );

for (int y = 0; y < 100000; y++) {
scene->addRect(0, y * 25, 40, 20);
}
view->setScene(scene);
// Tell the view to display only the actual scene-objects area
view->setSceneRect(0, 0, 40, 25*100000+20);

关于performance - QGraphicsScene,项目坐标影响性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6164543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com