Nic*_*kis 13 performance qt qgraphicsscene
使用下面的代码片段,我创建了一个包含100.000个矩形的场景.
表现很好; 视图没有延迟响应.
QGraphicsScene * scene = new QGraphicsScene;
for (int y = -50000; y < 50000; y++) {
scene->addRect(0, y * 25, 40, 20);
}
...
view->setScene(scene);
Run Code Online (Sandbox Code Playgroud)
而现在第二个片段很糟糕
for (int y = 0; y < 100000; y++) {
scene->addRect(0, y * 25, 40, 20);
}
Run Code Online (Sandbox Code Playgroud)
对于场景元素的前半部分,视图延迟响应鼠标和键事件,而另一半看起来似乎没问题?!?
前一场景有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;
...
Run Code Online (Sandbox Code Playgroud)
我有一个解决方案,但保证不会问我为什么这样有效,因为我真的不知道:-)
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1780 次 |
| 最近记录: |