Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-65779

QRect::normalized() doesn't preserve rect's size

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P5: Not important
    • None
    • 4.8.7, 5.9.3
    • Core: Other
    • 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-22934---, QTBUG-28851 and QTBUG-38653.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Unassigned Unassigned
              nizovn Nikolay Nizov
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes