With the below code snippet I create a scene with 100.000 rectangles.
The performance is fine; the view responds with no delays.
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);
}
对于场景元素的前半部分,视图会延迟对鼠标和键事件的响应,而对于另一半,它似乎还可以?!?
The former scene has sceneRect (x, y, w, h) = (0, -1250000, 40, 2499995).
The latter scene has sceneRect (x, y, w, h) = (0, 0, 40, 2499995).
我不知道为什么sceneect会影响性能,因为BSP索引是基于相对项目坐标的。
Am I missing something? I didn t find any information on the documentation, plus the Qt demo 40000 Chips also distributes the elements around (0, 0), without explaining the reason for that choice.
// 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;
...