[Qt-interest] Paint a QTextDocument with a Custom Pen
Josiah Bryan
jbryan at productiveconcepts.com
Wed Sep 16 04:22:15 CEST 2009
Josiah Bryan wrote:
> Evening, All -
>
> I'd like to draw a QTextDocument in a QGraphicsItem using a custom pen
> (e.g. to outline the text with, say, a 3px black outline to set it off
> from the background.) E.g.:
>
[snip]
> Is their any way to tell the documentLayout()->draw() method what pen to
> use or to force it to use the pen / brush on the painter? (And yes, I've
> googled, and I've tried drawing the QTextBlocks myself - but I want
> wordwrapping and I cant figure out how to wordwrap it myself from the
> QTextBlocks. Oh, and no, pCtx doesn't have a method for specifying the
> pen that I've seen. But I keep searching. Hence this email.)
>
In case anyone else stumbles upon the need to do word wrapping
themselves for a QTextDocument, I've gone ahead and implemented my own
somewhat-generic routines in a project I'm working on, hosted at google
code:
Project 'dviz', Line 609 (r25) of /trunk/src/items/TextboxContent.cpp
begins the layout routine. It stores the text as a list of strings with
associated format and position on screen. See the following link on
google code to jump right to that file/line:
http://code.google.com/p/dviz/source/browse/trunk/src/items/TextBoxContent.cpp?spec=svn25&r=25#609
Anyone with ideas for improvement - please let me know. I am by no means
a typography expert, text layout specialist, or anything of the like - I
just have a need for custom painting a QTextDocument, while retaining
word wrapping, so this is really just scratching my own itch. If it
helps others, all the better!
Interested in any feedback you may have.
Cheers!
-josiah
More information about the Qt-interest-old
mailing list