[Qt-interest] Finding the displayed width of rich text
John Posner
jjposner at optimum.net
Sat Dec 19 21:48:00 CET 2009
I've been using plain text to display a fraction as the text of a QLabel:
"2/5"
But now, I'd like to use rich text to make a better-looking fraction,
using the superscript-and- subscript technique:
"<sup>2</sup>/<sub>5</sub>"
I need to know the size of the displayed fraction, in order to select
the optimal point-size for the label. QFontMetrics.width() does the job
for the plain-text label, but for the rich-text label, it returns the
size of the 25-character string, not the size of the 3-character
superscript-and-subscript string.
I found a workaround: find the size of the QLabel widget itself, which
is just big enough to accommodate the rich-text label. But I'm looking
for other solutions (because I want to fiddle with the label's size).
Can anyone provide advice?
Tx,
John
More information about the Qt-interest-old
mailing list