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

QPainter::drawText() on X11: off-by-one error when painting to QPixmap compared to QBitmap

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • Some future release
    • 4.2.3
    • GUI: Painting
    • None

    Description

      Consider the following on X11:

      The same QPainter code is used to draw a rectangle and some text in a QPixmap and a QBitmap. In the resulting images, the rectangle is the same, but the text is off by one pixel in the vertical direction in the QPixmap compared to the QBitmap. The text should be painted the same in both images.

      Note that the off-by-one error only occurs if XRender is enabled. if XRender is disabled, the text is drawn exactly the same in the QPixmap as in the QBitmap.

      The following example demonstrates the problem:

      #include <QApplication>
      #include <QPainter>
      #include <QPixmap>
      #include <QBitmap>
      
      void draw_text(QPixmap* d) {
          QPainter p;
          p.begin(d);
          p.setRenderHint(QPainter::Antialiasing, false);
          p.setRenderHint(QPainter::TextAntialiasing, false);
          QFont fn = p.font();
          fn.setStyleStrategy(QFont::NoAntialias);
          fn.setPointSize(18);
          p.setFont(fn);
          p.drawRect(d->rect().adjusted(0, 0, -1, -1));
          p.drawText(20, 20, "test");
          p.end();
      }
      
      int main(int argc, char *argv[]) {
          QApplication a(argc, argv);
          QPixmap p(100, 100);
          QBitmap b(100, 100);
          p.fill(Qt::transparent);
          b.clear();
          draw_text(&p);
          draw_text(&b);
          p.save("pixmap.png", "PNG");
          b.save("bitmap.png", "PNG");
          return 0;
      }
      

      Attachments

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

        Activity

          People

            rodal Samuel Rødal
            sthomass Stian Sandvik Thomassen (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes