Is there a way to get the horizonal advance of every character in a string?
-
Hi,
I'm looking for something like GetPartialTextExtents() in wxWidgets or GDI+ MeasureCharacterRanges(). Does QT have something like that? QFontMetrics doesn't seem to.
Gerald
-
What's wrong with QFontMetrics::horizontalAdvance(QChar ch) ?
-
@Christian-Ehrlicher Nothing, except that I'm calling it over 600,000 times.
When I switched from individual character measuring to string measuring (getting each characters width) in wxWidgets, I got a 10x speed improvement.
Gerald
-
@GeraldBrandt said in Is there a way to get the horizonal advance of every character in a string?:
Nothing, except that I'm calling it over 600,000 times.
If you really need it then add a cache.
-
Hi
Just as a note
There is an overload that takes a QStringint horizontalAdvance(const QString &, int len = -1) const;
However, if that is faster then looping the string your self and call the QChar version i don't know.
-
Actually, 100% my fault. Things are plenty fast. I had an extra call to size() in my method that I didn't need, and that is a slow call.
Thanks,
Gerald