PDA

View Full Version : drawing formatted QTextDocument



tuli
14th July 2012, 15:05
I need to render a QTextDocument formatted by a QSyntaxHighlighter to a raw window.
I figured a way via



painter->translate(x, y);
QAbstractTextDocumentLayout::PaintContext cont;
document()->documentLayout()->draw(painter, cont);


but this doesnt allow for centering it in a QRect.
How could i do it like drawing a plain string with a QPainter?



painter->drawText(x,y,w,h,Qt::AlignLeft, mystr);



thanks,


edit:
for example, this doesnt work:

document()->drawContents(painter, QRect(x,y,w,h));

edit2:
Another problem is that the code in the very first code box doesnt use the font selected into QPainter... :(

wysota
14th July 2012, 16:02
Set the width of the document prior to using the layout.

tuli
14th July 2012, 16:27
that did the trick, thanks!




posts: 26,692
respect! O.O