Html text bounding rectangle
Code:
/* virtual */ const unsigned int ZeInfoItem::UpdateHeight(const unsigned int width)
{
document.setHtml(mTextComponent.getText());
document.setTextWidth(width);
mHeight = document.size().height();
return mHeight;
}
Here is a function to retrieve the height of an HTML text bounding rectangle.
Unfortunately it's quite slow, when called repetitively.
Do you have a better solution ?
Thanks.
Re: Html text bounding rectangle
Unfortunately it has to be slow, because the document has to be laid out. Try reducing the number of iterations.
Re: Html text bounding rectangle
Befor yo update the document.setTextWidth(width);
check the exist width ... large image or table ..
and its become slow if paitdevice go outside paint the width..
QGraphicsTextItem , QTextEdit or QTextBrowser, use a private class name QTextControl
this class is very large ....
to paint and edit text you need only QTextDocument,QTextCursor,QAbstractTextDocumentLay out
show and test http://www.qt-apps.org/content/show....?content=80234
Code:
/* QTextDocument *_d; */
QRectF TextWriter
::boundingRect() const {
if (_d) {
_d->adjustSize(); ///// !!!!!!
return Layout->frameBoundingRect(_d->rootFrame());
} else {
}
}
Re: Html text bounding rectangle
Thanks for replying,
I'm not sure I understood.
What impementation do you propose ?
Re: Html text bounding rectangle
Code:
painter.
setRenderHint(QPainter::Antialiasing,
false);
QFont & font
= getDisplayFont
();
font.setFamily("Arial");
font.setPointSize(8);
document.setDefaultFont(font);
document.setHtml(text);
ZeSmileyController::get()->InsertSmiley(document);
document.setTextWidth(textRect.width());
context.
clip = QRect(0,
0, textRect.
width(), textRect.
height());
painter.translate(textRect.x(), textRect.y());
document.documentLayout()->draw(&painter, context);
painter.restore();
I've come up with that implementation to display an HTML text paragraph.
I'm trying to display an ItemView of HTML items.
The performance are terrible at this point. Anyone has any idea to optimize this ? The paint event simply cannot lay the document at every painting event.
Re: Html text bounding rectangle
Try caching as much as you can. If the width didn't change, there is no need to rebuild the layout. I remember implementing a rich text delegate and it worked fine, so yours should too. You can also take a look at QwwRichTextButton from wwWidgets, it uses a QTextDocument internally to do rich text rendering, maybe you can steal some of my code...
Re: Html text bounding rectangle
Thanks wysota,
I've take a look at QwwRichTextButton source code.
Nice widget extension you've got here.
The biggest difference between your code and mine is that you "cache" the QTextDocument in every QwwRichTextButton.
In my case since I plan displaying like 10 000 items like this.
So in a widget context it's working fine since you'll draw one or two of these.
But in an massive itemview list you cannot do that.
Or I have to create a "pool" of textdocument :/. That's a lot of work just to display html paragraphes.
I guess if you can make a compilable example displaying an itemview of 10 000 paragrahes items without caching it I would shut my mouth :).
Re: Html text bounding rectangle
Quote:
Originally Posted by
bunjee
In my case since I plan displaying like 10 000 items like this.
So in a widget context it's working fine since you'll draw one or two of these.
But in an massive itemview list you cannot do that.
Yes, that's true, but you can still cache the results as pixmaps and only regenerate them when it is really needed.
Quote:
I guess if you can make a compilable example displaying an itemview of 10 000 paragrahes items without caching it I would shut my mouth :).
Sorry, no time to do that now :)
Re: Html text bounding rectangle
Pixmap buffering sounds like a good idea.
Where should I start ?