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

QFontMetrics::boundingRect(const QString &) to narrow with certain characters in the string

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.7.2
    • GUI: Text handling
    • None
    • Kubuntu 22.04. Noto Sans 10pt as System font
    • Linux/Wayland

    Description

      A string containing at least the two characters 🏡 and ☕ results in a bounding box with a far to small width. Other methods seem to provide the correct width.

      Example QWidgets Program:

      #include <QApplication>
      #include <QFontMetrics>
      #include <QPainter>
      #include <QWidget>
      
      class TestWidget : public QWidget {
      public:
          using QWidget::QWidget;
      
      protected:
          void paintEvent(QPaintEvent *event)
          {
              QString text = "🏡☕";
              QPainter painter{ this };
              QFontMetrics metric{ painter.font(), this };
              QRect box = metric.boundingRect(text);
              painter.fillRect(100 + box.x(), 100 + box.y(),
                               box.width(), box.height(),
                               QColor{ "lightgreen" });
              painter.drawText(100, 100, text);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          TestWidget 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

            esabraha Eskil Abrahamsen Blomfeldt
            jomatokic Johannes Matokic
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes