{
int colCount = 10;
int rowCount = 10;
int tileWidth = 32;
int tileHeight = 32;
// clear background
painter
->fillRect
(rect,
QBrush(Qt
::black));
//painter->translate(rect.width() / -2.0, rect.height() / -2.0);
painter
->setRenderHint
(QPainter::Antialiasing,
true);
pen.setStyle(Qt::DotLine);
pen.
setColor(QColor(Qt
::gray));
painter->setPen(pen);
int x, y, x2, y2;
y = 0; //painter->window().top();
y2 = y + (rowCount * tileHeight);
for(int c = 0; c <= colCount; c++)
{
x = c * tileWidth;
x2 = x;
painter->drawLine(x, y, x2, y2);
}
x = 0; //painter->window().left();
x2 = x + (colCount * tileWidth);// painter->window().right();
for(int r = 0; r <= rowCount; r++){
y = r * tileHeight;
y2 = y;
painter->drawLine(x, y, x2, y2);
}
}
void GameScene::drawBackground(QPainter *painter, const QRectF &rect)
{
int colCount = 10;
int rowCount = 10;
int tileWidth = 32;
int tileHeight = 32;
// clear background
painter->fillRect(rect, QBrush(Qt::black));
//painter->translate(rect.width() / -2.0, rect.height() / -2.0);
painter->setRenderHint(QPainter::Antialiasing, true);
QPen pen;
pen.setStyle(Qt::DotLine);
pen.setColor(QColor(Qt::gray));
painter->setPen(pen);
int x, y, x2, y2;
y = 0; //painter->window().top();
y2 = y + (rowCount * tileHeight);
for(int c = 0; c <= colCount; c++)
{
x = c * tileWidth;
x2 = x;
painter->drawLine(x, y, x2, y2);
}
x = 0; //painter->window().left();
x2 = x + (colCount * tileWidth);// painter->window().right();
for(int r = 0; r <= rowCount; r++){
y = r * tileHeight;
y2 = y;
painter->drawLine(x, y, x2, y2);
}
}
To copy to clipboard, switch view to plain text mode
So, is this normal? Or I must translate the painter to have {0,0} be the top left corner?
Bookmarks