PDA

View Full Version : Right justify QPainterPath addText



GimpMaster
20th January 2011, 16:09
Hello,

I'm using QPainterPath to draw my text so I can get nice outlined text that gets displayed over video. I'm using the addText(...) function and then the QPainter::drawPath.

Some of my text I would like to have right justified instead of left justified. Is this possible? Any other suggestions?

I want it to be outlined or stroked text so it has a 1 pixel black board around the white text otherwise I would just use the QPainter::drawText(...) function.

high_flyer
20th January 2011, 16:26
Did you try the alignment flags?
http://doc.trolltech.com/4.7/qpainter.html#drawText

GimpMaster
20th January 2011, 16:31
No, what I'm saying is, from my web searching is that the only way I can get pixel stroked text is by using a QPainterPath and using addText and NOT drawText...

addText does not have the alignment flags.

high_flyer
20th January 2011, 16:43
oops sorry, reading to fast.

Hmm... since you are not using drawText() you probably will have to justify your self.
But that should be rather easy - you have your paths bounding rect, so all you have to do is translate to "widget right edge" - "path_bounding_rect".

GimpMaster
20th January 2011, 16:53
Ahhh, very good idea.

I just have one more question. It doesn't seem like there is a way to clear the elements from the QPainterPath.

For example I have like 10 lines of text I would like to right justify. I would like to addText(...) get the bounding rect for that text and then translate the Painter path for each line. However there is no QPainterPath::clear() function. Does that mean I really need to construct a new QPainterPath object for each line? Seems kind of silly. What am I missing :)

Thanks

high_flyer
20th January 2011, 20:18
Currently from what I see in the docs you have to go the "long way".
But I don't think constructing a new path for each string is really more expensive than adding text to existing path, as addText() creates sub paths.
You think "text" but in reality this is just a bunch of paths - and you usually construct your path and draw it (fire and forget sort of), and not (re)use it like you (want to) do.