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

QPainter::drawText with rotated painter has incorrect spacing on Windows only

    XMLWordPrintable

Details

    Description

      On Windows only, the spacing between characters is often incorrect when using QPainter::drawText with a rotated QPainter. In the test application below, the drawn strings should be identical except for a small, almost unnoticeable rotation. As it is, it is clear that the spacing between the "w"'s and "i"'s is way off.

      main.cpp
      #include <QtGui>
      #include <QFont>
      
      class MyWidget : public QWidget {
      public:
        MyWidget(QWidget *parent = NULL) : QWidget(parent) {
          setFixedSize(100, 100);
        }
      
      protected:
        void paintEvent(QPaintEvent *) {
          QFont f;
          f.setFamily("Arial");
          f.setPixelSize(11);
      
          QPainter painter(this);
          painter.setFont(f);
          painter.setBrush(Qt::NoBrush);
          painter.setPen(Qt::SolidLine);
          painter.drawText(50, 50, "wiwi");
      
          painter.rotate(1.);
          painter.drawText(50, 70, "wiwi");
        }
      };
      
      int main(int argc, char **argv) {
        QApplication app(argc, argv);
        MyWidget w;
        w.show();
        return app.exec();
      }
      

      A screenshot of what this looks like on my machine is attached. Some things I have noticed:

      • It is fine on X11 (Ubuntu, at least) and Mac OS X.
      • It only affects certain fonts at certain sizes. If, for example, you change the font in the example to pixel size 12 or point size 11, it looks fine.
      • This may be a duplicate of QTBUG-20900. It certainly seems like the same behavior. I wasn't positive, however, so opened up a second bug and added reciprocal links.

      Attachments

        1. ss.png
          8 kB
          Dave Mateer

        Issue Links

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

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              dmateer Dave Mateer
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes