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

QTextLayout::maximumWidth() doesn't handle spaces correctly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.5.0 Beta1
    • 6.2.4, 6.3.2, 6.4.0 Beta4
    • GUI: Text handling
    • None
    • All
    • 4945fd93f1 (qt/qtbase/dev) 4945fd93f1 (qt/tqtc-qtbase/dev)

    Description

      QTextLayout::maximumWidth() doesn't handle correctly internal text spaces when wrapping is used.

      Test case

      #include <QGuiApplication>
      #include <QTextLayout>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          const QString text("text                                text");
      
          QTextLayout referenceLayout(text);
          referenceLayout.beginLayout();
          while (referenceLayout.createLine().isValid()) { }
          referenceLayout.endLayout();
      
          QTextLayout layout(text);
          layout.beginLayout();
          for (auto line = layout.createLine(); line.isValid(); line = layout.createLine())
              line.setLineWidth(40);
          layout.endLayout();
      
          qreal refMaxWidth = referenceLayout.maximumWidth();
          qDebug() << "reference maxwidth:" << refMaxWidth;
      
          qreal wrappedMaxWidth = layout.maximumWidth();
          qDebug() << "wrapped maxwidth:" << wrappedMaxWidth;
      
          Q_ASSERT(qFuzzyCompare(refMaxWidth, wrappedMaxWidth));
      
          return 0;
      }
      

      Output:

      reference maxwidth: 144.781
      wrapped maxwidth: 79.7813
      ASSERT: "qFuzzyCompare(refMaxWidth, wrappedMaxWidth)" in file ..\TextLayout\main.cpp, line 27
      

      Attachments

        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
              studiosus Vladimir Belyavsky
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes