PDA

View Full Version : Adding millions of GraphicsItems is slow



rk123
27th April 2009, 23:18
Hi,
I have code like this:

scene->set_brush(this->get_lp()->get_brush());
scene->set_pen(this->get_lp()->get_pen());
QListIterator<db_rect *> iter_rect(this->rect_list);
while(iter_rect.hasNext()) {
rect = iter_rect.next();
scene->addItem(rect);
}
QListIterator<db_box *> iter_box(this->box_list);
while(iter_box.hasNext()) {
box = (db_box *) iter_box.next();
scene->addItem(box);
}
QListIterator<db_path *> iter_path(this->path_list);
while(iter_path.hasNext()) {
path = iter_path.next();
scene->addItem(path);
}
QListIterator<db_polygon *> iter_polygon(this->polygon_list);
while(iter_polygon.hasNext()) {
polygon = iter_polygon.next();
scene->addItem(polygon);
}
QListIterator<db_text *> iter_text(this->text_list);
while(iter_text.hasNext()) {
text = iter_text.next();
scene->addItem(text);
}


Works great when I have thousands of objects. However, when I add millions, it is awfully slow. I am sure I am missing something. I was trying to figure out how to paint on a pixmap when using addItem but to no avail.
Please help.

Thanks -- RK

wysota
28th April 2009, 07:17
If you have millions of objects then unfortunately you have to go through those loops millions of times and there is not much you can do about it. You might just reduce slowdowns related to the architecture yourself - create a scene, add all the items and only then set the scene on a view. You might also try disabling indexing during addition of items although I'm not convinced this will help.