vql

22nd April 2008, 05:06

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

void MyWidget:: paintEvent(QPaintEvent *e)

{

QPainter p(this);

QRect r = QRect(100, 100, 400, 400);

p.setPen(Qt::red);

p.drawRect(r);

int x1, y1, x2, y2);

r.getCoords(&x1, &y1, &x2, &y2); // it will return x1=100, y1=100, x2=499, y2=499

p.setPen(Qt::green);

p.drawLine(x1, y1, x2, y1);

p.drawLine(x2, y1, x2, y2);

p.drawLine(x1, y2, x2, y2);

p.drawLine(x1, y1, x1, y2);

}

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

void MyWidget:: paintEvent(QPaintEvent *e)

{

QPainter p(this);

QRect r = QRect(100, 100, 400, 400);

p.setPen(Qt::red);

p.drawRect(r);

int x1, y1, x2, y2);

r.getCoords(&x1, &y1, &x2, &y2); // it will return x1=100, y1=100, x2=499, y2=499

p.setPen(Qt::green);

p.drawLine(x1, y1, x2, y1);

p.drawLine(x2, y1, x2, y2);

p.drawLine(x1, y2, x2, y2);

p.drawLine(x1, y1, x1, y2);

}

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