PDA

View Full Version : HTML text drawn with QPainter::drawText()



MarkoSan
18th January 2008, 12:31
Hi to all!

I have following situation: I have a merchandize description field in my database. This field's contens is HTML based text and I would like to draw it via QPaint::drawText(). Is this possible, and if it is, is HTML formatting smart to do inside paintEvent()?

patrik08
19th January 2008, 01:23
Is same as Print , have a look on... :
http://www.qt-apps.org/content/show.php/TextPrinter?content=62383



///// inside QWidget Hover Label
QString text_x = "Hello World!";
doc = new QTextDocument(this);
doc->setUndoRedoEnabled(false);
doc->setHtml("<p><span style=\"color:#000000; font-weight:600\">"+text_x+"</span></p>");
doc->setTextWidth(width());
doc->setUseDesignMetrics(true);
doc->setDefaultTextOption ( QTextOption (Qt::AlignHCenter ) );
//// height from doc QTextDocument
//// http://fop-miniscribus.googlecode.com/svn/trunk/fop_miniscribus.1.0.0/src/floating_box/floatdiagram.cpp
//////setMaximumHeight(DocumentHighgtActual());

QPainter *p = new QPainter(&PicsDocument);
p->setRenderHint(QPainter::Antialiasing, true);
doc->drawContents(p,clip);
p->end();

///// QPixmap PicsDocument contains image as html