Details
-
Bug
-
Resolution: Duplicate
-
P5: Not important
-
None
-
4.8.7, 5.9.3
-
None
Description
QRect::normalized() in case of negative rectangle's height/width returns rectangle, whose corresponding dimensions are larger by 2px. QRectF::normalized() works as expected.
Example:
#include <QRect> #include <QDebug> int main(int argc, char *argv[]) { QRect r(QPoint(0,0), QSize(-1,-1)); qWarning() << "in:" << r << "out:" << r.normalized(); qWarning() << "in:" << QRectF(r) << "out:" << QRectF(r).normalized(); return 0; }
Output:
in: QRect(0,0 -1x-1) out: QRect(-2,-2 3x3) in: QRectF(0,0 -1x-1) out: QRectF(-1,-1 1x1)
It looks like this function in such non-correctly working state is quite useless and can be potentially a source of bugs. For example, QPainter's code has it's own implementation of normalized() for correctness, see https://codereview.qt-project.org/173060. It would be nice to fix this behaviour for everyone.
Proposed possible fix is attached (Qt 5.9.3). Maybe It's also a solution for ------, QTBUG-28851 and QTBUG-38653.QTBUG-22934
Attachments
Issue Links
- duplicates
-
QTBUG-38653 QRect should change its way to compute the width and height, especially in QRect::normalized().
- Reported