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:


Qt Code:
  1. void ScrollTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
  2.  
  3. if(currentDocument){
  4.  
  5. painter->setRenderHint(QPainter::SmoothPixmapTransform);
  6.  
  7. painter->translate(0,-scrollValue);
  8.  
  9. painter->scale(renderScale.width(),renderScale.height());
  10.  
  11. QAbstractTextDocumentLayout::PaintContext pcontext;
  12. pcontext.palette.setColor(QPalette::Text, scrollScene->getDefaultTextColor());
  13.  
  14. pcontext.clip = QRectF(0,scrollValue/renderScale.height(),
  15. renderSize.width()/renderScale.width(),
  16. renderSize.height()/renderScale.height());
  17.  
  18. currentDocument->documentLayout()->draw(painter,pcontext);
  19.  
  20. }
  21. }
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