Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.8.4
-
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.