PDA

View Full Version : How to paint a formated text in a QPainterPath object



zade
26th May 2010, 10:23
when used QPainter Object, I can paint a formated text like below:

painter.addText(rect,flags,text);

and text can contain control char like '\n'.

while QPainterPath class does only have a simple interface like:addText(QPoint,QFont,QString).

So, how can't add formarted text to a QPainterPath object?

Thanks!

high_flyer
26th May 2010, 11:02
What it is you want to do?
Why QPainter::drawText() (not addText()) is not good for you?
Control chars such as '\n' can be used by both versions, since both use QString, in that sense, there is no difference between the two.

zade
27th May 2010, 02:29
What it is you want to do?
Why QPainter::drawText() (not addText()) is not good for you?
Control chars such as '\n' can be used by both versions, since both use QString, in that sense, there is no difference between the two.

I can use QPainterPath to get the text outline, while QPainter can't.

as my tested, QPainterPath does not supoort such path.addText(myPoint,myFont,"hello\n world!"); The control char '\n' will be ignored in above statment.

high_flyer
27th May 2010, 08:54
The control char '\n' will be ignored in above statment.
But that is not a visible character...
Wont breaking the string in to lines and creating one path per line do what you want?

zade
28th May 2010, 02:50
But that is not a visible character...
Wont breaking the string in to lines and creating one path per line do what you want?

That is the mathod i used just now; but what i like is QPanterPath provides interface like QPainter.

While GDIPLUS uses Graphics and GraphicsPath like QPainter and QPainterPath, while GraphicsPath has the adding formated text interface like in Graphics. So why QPainterPath does not provide such functions.

high_flyer
28th May 2010, 10:45
So why QPainterPath does not provide such functions.
Because they are meant for different things, this is why you have QPainter and QPainterPath.
QPainterPath is a PATH, not a PAINTER.
A path has nothing to do with text particularities.