Hello!
I'm writing a program that should render the text embedded in a QTextDocument on a QGraphicsView, the text must be scaled and smoothly scrolled.
To do this job I've inherited the class QGraphicsItem and implemented the funciont paint, after the item is added to a QGraphicsScene that calls the function advance() every 30 milliseconds.
here is the code of the paint function:
if(currentDocument){
painter
->setRenderHint
(QPainter::SmoothPixmapTransform);
painter->translate(0,-scrollValue);
painter->scale(renderScale.width(),renderScale.height());
pcontext.
palette.
setColor(QPalette::Text, scrollScene
->getDefaultTextColor
());
pcontext.
clip = QRectF(0,scrollValue
/renderScale.
height(),
renderSize.width()/renderScale.width(),
renderSize.height()/renderScale.height());
currentDocument->documentLayout()->draw(painter,pcontext);
}
}
void ScrollTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
if(currentDocument){
painter->setRenderHint(QPainter::SmoothPixmapTransform);
painter->translate(0,-scrollValue);
painter->scale(renderScale.width(),renderScale.height());
QAbstractTextDocumentLayout::PaintContext pcontext;
pcontext.palette.setColor(QPalette::Text, scrollScene->getDefaultTextColor());
pcontext.clip = QRectF(0,scrollValue/renderScale.height(),
renderSize.width()/renderScale.width(),
renderSize.height()/renderScale.height());
currentDocument->documentLayout()->draw(painter,pcontext);
}
}
To copy to clipboard, switch view to plain text mode
The matter is if the result is almost reasonable for light-weight documents and for low scale factor, the performances turn down even for a small portion of text (few lines) scaled and drawn in a window 800x600.
Did i forget some optimization? Are there ways for improve the draw algorithm (for example using a QGLWidget)?
Have you some hints or suggestions?
thanks for the attention
Regards
Bookmarks