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

QFontMetrics::elidedText() unnecessarily slow for long texts

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8.4
    • GUI: Text handling
    • None

    Description

      More a feature request:

      The following code

      #include <QApplication>
      #include <QFont>
      #include <QFontMetrics>int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QFont font = a.font();    QFontMetrics fm(font);    int len = 1;
          for (int i = 0; i < 10; ++i, len *= 10) {
              QString text(len,QChar('x'));
              QElapsedTimer timer;
              timer.start();
              fm.elidedText(text, Qt::ElideRight, 1000);
              qDebug() << i << len << timer.elapsed();
          }
      }
      

      creates the following output for me:

      0 1 41
      1 10 0
      2 100 0
      3 1000 0
      4 10000 7
      5 100000 72
      6 1000000 731
      7 10000000 6817
      8 100000000 74756

      i.e. the function run time is roughly linear in the length of the string, because it processes the whole string for the  this->width(from, layoutData->string.size()) <= width check in QTextEngine::elidedText()  (and probably more places)

         if (mode == Qt::ElideNone
              || this->width(from, layoutData->string.size()) <= width
              || to - from <= 1)
              return layoutData->string.mid(from, from - to);

      In  theory it should be possible to restrict this to (maybe a little more than) the target width.

      We run into it with the text annotations for compiler errors  in Creator's main editor, that show a few dozen characters at most, whereas the compiler error nowadays can be tens of thousands of characters.

      We can work around the issue by truncating the string before passing to QFontMetrics::elidedText(), but it would be nice if this could be done on the Qt side.

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            hjk hjk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes