inline QRect::QRect(int aleft, int atop, int awidth, int aheight)
{
x1 = aleft;
y1 = atop;
x2 = (aleft + awidth - 1);
y2 = (atop + aheight - 1);
}
QRect QRect::normalized() const
{
QRect r;
if (x2 < x1 - 1) { // swap bad x values
r.x1 = x2;
r.x2 = x1;
} else {
r.x1 = x1;
r.x2 = x2;
}
if (y2 < y1 - 1) { // swap bad y values
r.y1 = y2;
r.y2 = y1;
} else {
r.y1 = y1;
r.y2 = y2;
}
return r;
}
rect(0,0,-2,-2).normalized() = rect(-3, -3, 4,4)
多余的不说,看代码即可。
这儿补充几点:
1.rect(0,0,1,1)的起始位置和结束位置是一样的
2.setX(2) 后不仅仅x的值改变,width的也会改变,原因是 结束点没有改变; 若想移动rect 使用moveTo 等函数
2.1 moveTo(移动原点) moveLeft(移动左边) moveTop(移动下边) moveTopLeft(同moveTo ) 、这些都是在不改变size的前提下mov