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

QRect with negative width/height results in the pen being drawn in the wrong place

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 4.8.4, 5.0.0 Beta 2
    • GUI: Painting
    • None
    • Windows 7

    Description

      When a QRect with negative width and/or height is drawn with QPainter::drawRect(const QRectF &rect), the pen is drawn in the incorrect place. See the following code for an example. It draws one QRect with negative width/height on the left, and one normalized QRect on the right. The left one's brush is drawn correctly, but the pen puts the top left corner one pixel down and to the right. The attached picture is an enlargement of the result so that you can clearly see the result.

      // Qt 5 code
      
      #include <QtGui>
      #include <QtWidgets>
      
      class PainterWidget : public QWidget
      {
          void paintEvent(QPaintEvent *)
          {
              QPainter painter(this);
              painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
              QRect rectLeft(100, 100, -50, -50);
              QRect rectRight(200, 100, -50, -50); // same width/height as rectRight
              painter.drawRect(rectLeft);
              painter.drawRect(rectRight.normalized());
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          PainterWidget widget;
          widget.show();
      
          return a.exec();
      }
      

      Attachments

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

        Activity

          People

            sletta Gunnar Sletta
            aprechtl Anthony Prechtl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes