PDA

View Full Version : Fit text to space



Coises
30th January 2010, 01:49
Given a QString, a QFont and a QRect (or a QLabel), what is the simplest way to find the largest QFont::setPixelSize that can be set so that the QString, whien rendered in the QFont, will fit within the space (QRect or already sized QLabel)?

If there is no direct way to do it... what is the Qt equivalent of Windows’ GetTextExtentPoint32 (http://msdn.microsoft.com/en-us/library/dd144938.aspx)?

ChrisW67
1st February 2010, 08:15
I'm not aware of any one call that gives the answer you seek for font size.

You should look at QPainter::boundingRect(), QFontMetrics::boundingRect(), QFontMetrics::size(), and friends for inspiration.