I have the following code that render a 10 x 10 grid, I was expecting the grid start at {0, 0}, which should be the top left of the window, but the result is that {0, 0} is the center of the window.

Qt Code:
  1. void GameScene::drawBackground(QPainter *painter, const QRectF &rect)
  2. {
  3. int colCount = 10;
  4. int rowCount = 10;
  5. int tileWidth = 32;
  6. int tileHeight = 32;
  7.  
  8. // clear background
  9. painter->fillRect(rect, QBrush(Qt::black));
  10.  
  11. //painter->translate(rect.width() / -2.0, rect.height() / -2.0);
  12.  
  13. painter->setRenderHint(QPainter::Antialiasing, true);
  14.  
  15. QPen pen;
  16. pen.setStyle(Qt::DotLine);
  17. pen.setColor(QColor(Qt::gray));
  18. painter->setPen(pen);
  19.  
  20. int x, y, x2, y2;
  21.  
  22. y = 0; //painter->window().top();
  23. y2 = y + (rowCount * tileHeight);
  24. for(int c = 0; c <= colCount; c++)
  25. {
  26. x = c * tileWidth;
  27. x2 = x;
  28.  
  29. painter->drawLine(x, y, x2, y2);
  30. }
  31.  
  32. x = 0; //painter->window().left();
  33. x2 = x + (colCount * tileWidth);// painter->window().right();
  34. for(int r = 0; r <= rowCount; r++){
  35. y = r * tileHeight;
  36. y2 = y;
  37. painter->drawLine(x, y, x2, y2);
  38. }
  39. }
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?

shot.jpg