PDA

View Full Version : Problem with QTextDocument::drawContents(....)



zgulser
18th December 2013, 16:09
Hi,

I'm unable to set display messages exchanged between to clients if I use QTextDocument::drawContents(...). But it's ok to use QPainter::drawText(...) method. Please look at the following code;



QRect messageContentRect = messageFontMetrics.boundingRect(textOffset*4,
rect.top() + textHeightInPixels + 13,
rect.width() - (textOffset*4) - dateTimeTextWidthInPixels - 5 - 10 , 0,
Qt::AlignLeft | Qt::AlignTop | Qt::TextWrapAnywhere,
messageContent);

painter->setFont(messageFont);
painter->setPen(QColor("#363636"));
QTextDocument *doc = new QTextDocument();
doc->setHtml(messageContent);
//painter->drawText(messageContentRect, Qt::AlignLeft | Qt::AlignTop |Qt::TextWrapAnywhere, messageContent, &actuallyUsedRectForMessage); **** THIS IS OK
painter->translate( messageContentRect.topLeft() );
painter->translate( messageContentRect.bottomRight() );
doc->drawContents(painter, messageContentRect); //**** THIS IS NOT OK



I want to use QTextDocument because I want to insert image for smileys. Any ideas?

Regards, Zeki

Added after 4 minutes:

This link is exactly describes what I want...

http://qt-project.org/forums/viewthread/30472

zgulser
22nd December 2013, 08:03
Nothing yet?

ChrisW67
22nd December 2013, 11:12
What do you expect? You have not told us what, "THIS IS NOT OK" means.

You get the text an no images?
You get nothing?
You get the raw HTML?
Sure the HTML is valid?
Have to tried without specifying a clipping rectangle?
What else have you tried to debug it?