how to speed up when I need to draw huge number of objects in a view?
-
how to speed up when I need to draw huge number of objects in a view?
currently, I use QGraphicsView and put the objects into a QGraphicSneces ,however when the object number hits 50000000 , it takes lot of time.
///below shows my code:int main(int argc, char *argv[])
{QApplication app(argc, argv); QMainWindow window; window.show(); QGraphicsScene* scene = new QGraphicsScene(); int count = 3000; int step = 10; for (int i=0; i<count; i++){ for (int j=0; j<count; j++) { int rand_x = step*i; int rand_y = step*j; QGraphicsRectItem* rect = new QGraphicsRectItem(); rect->setRect(rand_x,rand_y,100,100); scene->addItem(rect); } } QGraphicsView * view = new QGraphicsView(scene); //view->setScene(scene); //view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); view->show(); window.setCentralWidget(view); return app.exec();
}
-
@vigi said in how to speed up when I need to draw huge number of objects in a view?:
when the object number hits 50000000 , it takes lot of time.
50 million is a lot! Your computer will probably run out of resources.
A 1080p screen only has 2 million pixels and a 4K screen only has 8 million pixels, so you can't possibly display 50 million rectangles on the screen.
how to speed up when I need to draw huge number of objects in a view?
Don't draw all 50 million at the same time. Only draw the objects that are inside (and near) your viewport. When the user pans around, draw new objects and delete old ones.
-
@vigi said in how to speed up when I need to draw huge number of objects in a view?:
can you show me an example?
Can you try it yourself first?
Why do you need so many objects, anyway?