Why does QRect isValid return false?
-
I have the following:
QRect rctSection; rctSection.setWidth(mszOffscreen.width()); rctSection.setTop((intViewMax - 1) * mptPixelsPerBSCAN.y()); rctSection.setBottom((intViewMin - 1) * mptPixelsPerBSCAN.y());
Line 1, rctSection created and contains all 0's.
Line 2, width is set to 72
Line 3, top is set to 3998
Line 4, bottom is set to 0After this I use isValid to test geometry:
if ( rctSection.isValid() == true ) {
It doesn't get into the scope of the condition indicating that isValid has returned false. Why? In the debugger, rctSection shows:
x1: 0 y1: 3998 x2: 71 y2: -1
Why does y2 contain 1 ?
I need to set the bottom and top and not setHeight, is Bottom expected to be greater than Top ?
[Edit] It appears this is the problem, having switch around the contents of setTop and setBottom it works.
-
@SPlatten said in Why does QRect isValid return false?:
for some reason bottom cannot be greater than top, switch around values and now its valid.
This is because it is the wanted behavior(cf documentation)
A valid rectangle has a left() <= right() and top() <= bottom(). Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).
-
@SPlatten said in Why does QRect isValid return false?:
its that strange tho, because the default coordinate system starts at 0,0 top left, the term top implies it is higher than bottom, which obviously isn't the case.
No, that is totally conform to Qt coodinates system:
Top is lower than Botton and Left is lower than Right