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

QPainter drawRect() fills rotated and scaled rectangles incorrectly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 4.8.4, 5.0.2, 5.1.0 Beta 1
    • GUI: Painting
    • None
    • Qt 5.1.0 built from git for Mac OS X, Ubuntu Qt 5.0.2
    • fdd843d5a76f2bba5c4ebdd5813c97f5105c5765

    Description

      QPainter draws the fill of rectangles incorrectly if the QPainter coordinate system has been rotated 45 degrees and scaled. The stroke of the rectangle is drawn correctly, but the fill area is oversized. This only happens in 45 degrees, other angles are drawn correctly. Here's a code clip, while there is an attachment with full example.

      QPainter p(this);
      p.rotate(45);
      p.scale(2, 1);
      p.setBrush(Qt::red);
      p.drawRect(50, 0, 100, 50);
      

      The attached picture shows the result. The red rectangle is drawn with rotation of 45 degrees. The green rectangle is drawn with rotation of 45.0001 degrees.

      The workaround is to rotate by 45.0001 degrees. Also, fillRect() works correctly. However, fillRect() can't be used when rounded rectangles are needed. In that case, one needs to call drawRoundedRect(), which also has this bug.

      The bug can be seen in Mac with the latest Git stable version. It is also present in the Ubuntu Qt 5.0.2 version. I think I saw this bug in Qt 4.8, too.

      Attachments

        1. main.cpp
          0.6 kB
        2. screenshot.png
          screenshot.png
          4 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sletta Gunnar Sletta
            kpihkala Kari Pihkala
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes