title: How to use QPainter::setTransform in paint() in Qt?
body: <p>I have a simple <code>QGraphicsView</code> with text written over it.That text is wrapped under a bounding rect. I have truncated a text using <code> QFontMetrics::elidedText</code>.<br />
  When initially view gets loaded, it shows all truncated text properly. But when I <code>zoom-in</code> only few truncated text gets visible. If for few more times I <code>zoomed-in</code>, then some times it shows all the truncated text and some times , it never shows any truncated text.<br />
  Before truncated text code gets added, <code>zoom-in</code> was working properly.</p>
  <p>widget.cpp</p>
  <pre><code>  void widget::ZoomIn()
    {
        double scaleFactor = 1.1;
        view-&gt;scale(scaleFactor,scaleFactor);
    }
  void Widget::on_textButton_clicked()
  {
      //logic to get string s and its co-ordinates firstPos and secondPos
      Text* t = new Text() ;
      QGraphicsTextItem* text = t-&gt;drawText(s,firstPos,secondPos,50,40);
      scene-&gt;addItem(text);
  }       
    
  </code></pre>
  <p>Text.cpp</p>
  <pre><code>Text::Text(const QString &amp;text,int left,int top,int width,int height)
      : QGraphicsTextItem (text),currentString(text),
      Left(left),Top(top),Width(width),Height(height)
  {}     
  
  Text::Text(){}
  
  QGraphicsTextItem  *Text::drawText(QString s, int left,int top,int width,int height)
  {
      QGraphicsTextItem  *text = new Text(s,left,top,width,height);
      return text;
  }     
  
  void Text::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  {
      Q_UNUSED(option);
      Q_UNUSED(widget);
  
      QFont defaultFont = QApplication::font();
      QFontMetrics fm = QFontMetrics(defaultFont);
      QRect rect = QRect(Left,Top,Width,Height);
      QString elidedText = fm.elidedText(currentString, Qt::ElideLeft,rect.width());
      
      QTransform trans = view-&gt;transform();
      QTransform prevTrans;
      painter-&gt;setTransform(trans);
      painter-&gt;drawText(rect,Qt::AlignRight,elidedText);
      painter-&gt;setTransform(prevTrans);
      
  }     
    
  </code></pre>
  <p>I understood that,  in <code>zoom-in</code> I am changing transformation and painter is drawing on old transformation. So I have to take transformation from <code>view</code> and set it with <code>painter</code> then <code>drawText()</code> and then set <code>painter</code> transformation as previous transformation.<br />
  I did , but still problem persist.</p>