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

QFontMetrics reports wrong size for substitution (box) character

    XMLWordPrintable

Details

    Description

      In the example below, the box-character that substitutes glyphs that are not part of the installed fonts

      #include <QtGui>

      class Widget : public QWidget
      {
      public:
      Widget()
      {
      }

      void setString(const QString &str)

      { string = str; update(); }

      protected:
      void paintEvent(QPaintEvent *event)
      {
      QPainter painter(this);
      int x = 0;
      int y = painter.fontMetrics().height();
      for (int c = 0; c < string.length(); ++c)

      { QChar ch = string.at(c); qDebug() << ch.unicode() << painter.fontMetrics().width(); painter.drawText(x, y, ch); x += painter.fontMetrics().width(); }

      }

      private:
      QString string;
      };

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QFont font("Tahoma", 36);
      a.setFont(font);

      QString unicode;
      unicode += QChar(0x0061);
      unicode += QChar(0x028c);
      unicode += QChar(0x0303);
      unicode += QChar(0x0020);
      unicode += QChar(0x0303);
      unicode += QChar(0x4100);
      unicode += QChar(0x901F);
      unicode += QChar(0x3100);
      unicode += QChar(0x0010);
      unicode += QChar(0x00CA);
      unicode += QChar(0xF053);
      unicode += QChar(0x2112);
      unicode += QChar(0x0062);

      QLineEdit le;
      le.setText(unicode);

      QLabel label;
      label.setText(unicode);

      Widget w;
      w.setString(unicode);

      w.show();
      label.show();
      le.show();

      return a.exec();
      }

      When turning font subtitution off, then QLineEdit and QLabel render the text with proper spacing, but QFontMetrics still returns a value that is too small.

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            vhilshei Volker Hilsheimer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes