I have been trying to use QGraphicsScene to create editable grid using following code:
int w = 5;
int h = 5;
//QRect r(0, 0, w*1680, h*800);
//scene->setSceneRect(r);
//scene->setBspTreeDepth(5);
//scene->setItemIndexMethod(QGraphicsScene::NoIndex);
QTime t;
for(long i = 0; i < 800; ++i) {
t.restart();
for(long j = 0; j < 1680; ++j) {
QGraphicsItem *item = scene->addRect(j*w, i*h, w, h, pen, brush);
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
}
qDebug() << "Elapsed Time: " << t.elapsed();
}
//scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
setScene(scene);
//setSceneRect(0, 0, 200, 200);
As can be seen from the code, there are approximately 1 million rectangle in the scene. Time to add new item seems to increase polynomially rather than logarithmically as described in the Qt documentation. Am I doing something obviously wrong?