Number of characters that fit into given width
-
I would like to be able to determine, given a
string
(QString
) that is supposed to be displayed within a givenwidth
(qreal
) area, how many of its characters would fit without overflowing that width.Is there any helper class / function that I can use to get this information, or do I need to create my own? If I do, what measurements should I include in this calculation? I have access to the
QFont
andQFontMetrics
objects that will be used.Thank you.
-
Something like http://doc.qt.io/qt-5/qfontmetrics.html#elidedText ?
-
Maybe yes. Most likely to work.
The problem would be if
::ElideNone
does not work as expected... Also, it would be better if I didn't have to make anotherQString
in order to get just the number of characters.But I'll give it a go.
Thank you.
-
@VRonin said in Number of characters that fit into given width:
Something like http://doc.qt.io/qt-5/qfontmetrics.html#elidedText ?
Turns out it will not work for me.
The
QString
returned includes the ellipsis and there is no way to avoid them, because passingQt::ElideNone
means "do not truncate" instead of "omit the ellipsis" (as I feared).