Qt-interest Archive, March 2007
Text String bounding box and width of QTextEdit
Message 1 in thread
Hi, I'm trying to create a QTextEdit widget that is just wide enough
to contain a string which is always a fixed length. The rendered width
of the text varies, because the font can change, but I want the
QTextEdit which displays it to be just large enough to contain the
string.
The executing QFontMetrics boundingRect ().width() gives a pixel width
of the string, but it's not wide enough. I'm still getting text
wrapped to the next line. Adding extra space to that solves the
problem, but it seems like a clunky solution. Depending on the font
the extra space on the right varies in size.
Am I doing this the best way, or is there some other way to calculate
the minimum width of a QTextEdit widget which will contain a string?
Thanks,
--
[ signature omitted ]