void drawLines
(QPainter *painter, QVarLengthArray<QLineF,
100>
&lines
){ painter->drawLines(lines.data(), lines.size());
}
void setupArray(QVarLengthArray<QLineF, 100> &lines){
const int gridSize = 25;
qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
for (qreal x = left; x < rect.right(); x += gridSize)
lines.
append(QLineF(x, rect.
top(), x, rect.
bottom()));
for (qreal y = top; y < rect.bottom(); y += gridSize)
lines.
append(QLineF(rect.
left(), y, rect.
right(), y
));
}
painter
->setPen
(QPen(Qt
::darkGreen,
0));
QVarLengthArray<QLineF, 100> lines;
setupArray(lines);
drawLines(painter, lines);
}
void drawLines(QPainter *painter, QVarLengthArray<QLineF, 100> &lines){
painter->drawLines(lines.data(), lines.size());
}
void setupArray(QVarLengthArray<QLineF, 100> &lines){
const int gridSize = 25;
qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
for (qreal x = left; x < rect.right(); x += gridSize)
lines.append(QLineF(x, rect.top(), x, rect.bottom()));
for (qreal y = top; y < rect.bottom(); y += gridSize)
lines.append(QLineF(rect.left(), y, rect.right(), y));
}
void drawBackground(QPainter *painter, const QRectF &rect){
painter->setPen(QPen(Qt::darkGreen,0));
QVarLengthArray<QLineF, 100> lines;
setupArray(lines);
drawLines(painter, lines);
}
To copy to clipboard, switch view to plain text mode
Bookmarks