I don't understand about drawRect. Please see this example:

Qt Code:
  1. void MyWidget:: paintEvent(QPaintEvent *e)
  2. {
  3. QPainter p(this);
  4. QRect r = QRect(100, 100, 400, 400);
  5. p.setPen(Qt::red);
  6. p.drawRect(r);
  7.  
  8. int x1, y1, x2, y2);
  9. r.getCoords(&x1, &y1, &x2, &y2); // it will return x1=100, y1=100, x2=499, y2=499
  10. p.setPen(Qt::green);
  11. p.drawLine(x1, y1, x2, y1);
  12. p.drawLine(x2, y1, x2, y2);
  13. p.drawLine(x1, y2, x2, y2);
  14. p.drawLine(x1, y1, x1, y2);
  15. }
To copy to clipboard, switch view to plain text mode 

Please tell me why 2 rectangle not overlap? I really not understand about the meaning of drawRect function.