PDA

View Full Version : QTextDocument - color, font



kemp
24th January 2007, 11:28
Hi!

I have a syntax highlighted QTextEdit. Is there a way to get the information: font,color..
out of the QTextDocument for each character.
So I want to get this information out of the editor->document ().

Is that possible.

Thanks.

jpn
24th January 2007, 12:16
Are you using QSyntaxHighlighter?

you can query the current formatting and user data using the format()

kemp
24th January 2007, 12:43
Thank you for your answer. Does that mean that I still need QTextEdit to aces the highlighter,
or is there a way to do that through the document alone?

jpn
24th January 2007, 13:16
Could you please explain the task? For what do you actually need all the colors?

For syntax highlighting purpose, QSyntaxHighlighter can do those pretty handy; format() & setFormat().

If you really need to manually extract the same information, I think you should first retrieve the corresponding QTextBlock, then construct a QTextCursor for it, move it to the correct position and then ask for it's format.

kemp
24th January 2007, 13:24
I have a print preview. I get the document and in paintevent I iterate through the textblocks and through text in each textblock. Now I want to make everything in color like there is in texteditor that i highlighted with the syntaxhighlighter.

jpn
24th January 2007, 13:39
Maybe you could get away with calling QTextDocument::drawContents() with a painter having a suitable scaling? That's just an idea, I don't know if it would work as desired..

kemp
24th January 2007, 13:51
Thanks for your help.