[Qt-interest] text dimensions ?

ygor at comcast.net ygor at comcast.net
Tue Mar 17 16:39:06 CET 2009


Have you considered 

void QPainter::drawText ( const QRect(F) & rectangle, int flags, const QString & text, QRect(F) * boundingRect = 0 ) 

?

<http://doc.trolltech.com/4.5/qpainter.html#drawText-10>
<http://doc.trolltech.com/4.5/qpainter.html#drawText-11>

----- Original Message -----
From: Martin Schröer <gordon at gordonswelt.de>
To: QT Interest List <qt-interest at trolltech.com>
Sent: Tue, 17 Mar 2009 15:24:42 +0000 (UTC)
Subject: Re: [Qt-interest] text dimensions ?

Well, okey. I thought of this approach myself but discarded it for being 
... dirty.
No better way of achieving it ?

Anyway, before i forget:
Thank you Jesus, for your very quick reply !

Martin

Jesús Fernández schrieb:
> So, you need to try diferent dimesions and stop at the maximum size:
>
> /For example/
> void GraphicsShapeItem::resized()
> {
>     QRectF r=boundingRect();
>     QFont font;
>     QFontMetrics fontMetrics;
>     QString text=tr("Sample text");
>     int height, width;
>
>     do {
>         font.setPointSize(font.pointSize()+1);
>         fontMetrics=QFontMetrics(font);
>         height=fontMetrics.height();
>         width=fontMetrics.width(text);
>     }while(r.width>width && r.height>height);
> }
>
> On Tue, Mar 17, 2009 at 4:06 PM, Martin Schröer <gordon at gordonswelt.de 
> <mailto:gordon at gordonswelt.de>> wrote:
>
>     Yes, this is nice - but only for the 'to' direction.
>     What if i have a rectangle in which i want to render a text given ?
>     How to find out what font size to use ?
>
>
>     Martin
>
>     Jesús Fernández schrieb:
>     > Read this:
>     >
>     > http://doc.trolltech.com/4.5/qfontmetrics.html
>     >
>     > Regards
>     >
>     > On Tue, Mar 17, 2009 at 3:50 PM, Martin Schröer
>     <gordon at gordonswelt.de <mailto:gordon at gordonswelt.de>
>     > <mailto:gordon at gordonswelt.de <mailto:gordon at gordonswelt.de>>>
>     wrote:
>     >
>     >     Hi list.
>     >
>     >     I have to drawText on a GraphicsScene.
>     >     Does anybody know a good practice to do this, considering the
>     >     [dynamic]
>     >     size of the text given to be drawn ?
>     >     I want to have the text fill a certain area in original
>     scale, plus
>     >     having it resize along with the whole scene,
>     >     so e.g. it always fills the same region within the scene.
>     >
>     >     Like giving a text 'rate this scene 'scary'', being always shown
>     >     in the
>     >     bottom right corner of the scene
>     >     within a region that is scene.width() /4, scene.height() /4.
>     >
>     >     I don't have troubles getting the size of a bounding rect
>     for doing
>     >     that, what gives me headaches is
>     >     how to find out which size the text has or has to have,
>     still being
>     >     drawn in aspect when the scene
>     >     dimensions changes.
>     >
>     >     Any help, as always, highly appreciated.
>     >
>     >     Martin
>     >     _______________________________________________
>     >     Qt-interest mailing list
>     >     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     <mailto:Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>>
>     >     http://lists.trolltech.com/mailman/listinfo/qt-interest
>     >
>     >
>
>     _______________________________________________
>     Qt-interest mailing list
>     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list