PDA

View Full Version : QRectF top and bottom



mastupristi
2nd November 2014, 00:39
I have tried this:

QRectF rect(QPointF(0.0, -35.0), QPointF(90.0, 0.0));
qDebug() << "RectF " << rect;
qDebug("bottom %f top %f", rect.bottom(), rect.top());


the output is:

RectF QRectF(0,-35 90x35)
bottom 0.000000 top -35.000000


Is that correct? I expected bottom -35 and top 0
where am I wrong?

best regards
max

wysota
2nd November 2014, 09:00
Yes, this is correct. QRectF expects the top left corner as the first argument and bottom right one as the second argument. If you don't follow that order you have to normalize the rectangle by calling QRectF::normalized().

mastupristi
2nd November 2014, 11:45
Yes, this is correct. QRectF expects the top left corner as the first argument and bottom right one as the second argument. If you don't follow that order you have to normalize the rectangle by calling QRectF::normalized().

The I have modified my example:


QRectF rect(QPointF(0.0, -35.0), QPointF(90.0, 0.0)); // wrong
QRectF rect_n = rect.normalized(); // wrong
QRectF rect_a(QPointF(0.0, 0.0), QPointF(90.0, -35.0)); // OK
QRectF rect_an = rect_a.normalized(); //wrong
qDebug() << "rect " << rect;
qDebug() << "rect norm " << rect_n;
qDebug() << "rect a " << rect_a;
qDebug() << "rect an " << rect_an;
qDebug("rect bottom %f top %f", rect.bottom(), rect.top());
qDebug("rect norm bottom %f top %f", rect_n.bottom(), rect_n.top());
qDebug("rect a bottom %f top %f", rect_a.bottom(), rect_a.top());
qDebug("rect an bottom %f top %f", rect_an.bottom(), rect_an.top());


and the output is now:

rect QRectF(0,-35 90x35)
rect norm QRectF(0,-35 90x35)
rect a QRectF(0,0 90x-35)
rect an QRectF(0,-35 90x35)
rect bottom 0.000000 top -35.000000
rect norm bottom 0.000000 top -35.000000
rect a bottom -35.000000 top 0.000000
rect an bottom 0.000000 top -35.000000


the normalized rectangle is the same of the non-normalized.
rect_a is declared correctly and is ok.
the normalize version of rect_a is again wrong. This seems ok since reading the doc qrectf.html#normalized the rect is normalized if the width or height is negative, and rect_a has negative height, but is correctly defined

so the question is where am I wrong with normalized method?

best regards
max

wysota
2nd November 2014, 12:59
rect is already normalized so no change here is expected. rect_a is not normalized thus normalizing it yields a normalized rectangle.

I'd like to point out that the y axis is oriented downwards so -35 is over 0. Thus bottom returns 0 and not -35.