Number of characters that fit into given width
-
wrote on 1 Oct 2018, 16:01 last edited by
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.
-
wrote on 1 Oct 2018, 16:35 last edited by VRonin 10 Jan 2018, 16:35
Something like http://doc.qt.io/qt-5/qfontmetrics.html#elidedText ?
-
wrote on 1 Oct 2018, 18:47 last edited by Arthur Araruna 10 Jan 2018, 18:51
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.
-
Something like http://doc.qt.io/qt-5/qfontmetrics.html#elidedText ?
wrote on 1 Oct 2018, 19:20 last edited by Arthur Araruna 10 Mar 2018, 19:07@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).
2/4