{
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);
}
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);
}
To copy to clipboard, switch view to plain text mode
Bookmarks