Let's paint a few objects consisting of a large number of lines:
static const int SIZE = 100; static const int MARGIN = 10; static const int FIGURE_COUNT = 5; static const int LINE_COUNT = 500; for(int figureNum = 0; figureNum < FIGURE_COUNT; ++figureNum) { QPainterPath path; path.moveTo(0, 0); for(int i = 0; i < LINE_COUNT; ++i) { path.lineTo(qrand() % SIZE, qrand() % SIZE); } QGraphicsPathItem *item = scene.addPath(path); item->setPos(figureNum * (SIZE + MARGIN), 0); }
For each item, we first create a QPainterPath and set the current position to (0, 0). Then, we use the qrand() function to generate random numbers, apply the modulus operator (%) to produce a number from 0 to SIZE (excluding ...