[Qt-interest] Qt-interest Digest, Vol 14, Issue 67
Ross Driedger
ross at earz.ca
Thu Jan 14 15:19:33 CET 2010
On 14-Jan-10, at 3:56 AM, qt-interest-request at trolltech.com wrote:
> Message: 2
> Date: Thu, 14 Jan 2010 14:53:41 +0900
> From: Paul England <pengland at cmt-asia.com>
> Subject: [Qt-interest] Getting the width of the font w/ QFontMetrics
> To: qt-interest at trolltech.com
> Message-ID: <4B4EB165.2050307 at cmt-asia.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> This never works for me:
>
> QFont font( "Tahoma", 10 );
> QLineEdit* line_edit;
> line_edit->setText( "Blah" );
> line_edit->setFont( font )
[...]
>
> // It's always too narrow.
Hi Paul,
I've spent the last month working on a component that does music
notation so I've had a bit of real world experience on this issue. I
wrote some debug code, (that is too large to post here) that builds a
QRect around each character as I draw it to a QGraphicsView and my
spacing and placing (which is crucial to my project); the versions I
am using are 4.5.3 and 4.6.0 on xp, Vista, MacOs, and SUSE.
The returns from boundingRect() have been very accurate for me. What
you might be missing is the spacing between characters when text is
rendered. Perhaps if you were to take the bounding width of a string
like "O O" and the width of 'O', subtract twice the second from the
first, you will get some idea of how much screen real estate the font
engine gives to the space.
I'm not too certain whether this addresses your issue.
Ross
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100114/597d8c34/attachment.html
More information about the Qt-interest-old
mailing list