title: How to Paint QTreeview content
body: <p>I'm trying to paint the content of a QTreeview in a QPixmap in order to render it in another QWidget and to print it.</p>
  
  <p>Currently my code looks like that :</p>
  
  <pre><code>QPixmap PrintWidget::getTreeView(QTreeView* treeview){
  
      QAbstractItemView::ScrollMode scrollMode = treeview-&gt;verticalScrollMode();
  
      treeview-&gt;selectionModel()-&gt;setCurrentIndex(QModelIndex(),QItemSelectionModel::Clear);
      treeview-&gt;setVerticalScrollMode(QTreeView::ScrollPerPixel);
  
      int width = treeview-&gt;viewport()-&gt;size().width();
      int scrollMax = treeview-&gt;verticalScrollBar()-&gt;maximum();
      int height = treeview-&gt;maximumViewportSize().height() + scrollMax;
  
      int currentPosition = treeview-&gt;verticalScrollBar()-&gt;sliderPosition();
  
      treeview-&gt;verticalScrollBar()-&gt;setSliderPosition(0);
  
      QPixmap pixmap(width,height);
  
      QRegion region(0,0,width,height);
      QPainter painter(&amp;pixmap);
  
      treeview-&gt;viewport()-&gt;render(&amp;painter,QPoint(),region,
                                   RenderFlags(QWidget::DrawChildren|QWidget::IgnoreMask));
  
      treeview-&gt;verticalScrollBar()-&gt;setSliderPosition(currentPosition);
      treeview-&gt;setVerticalScrollMode(scrollMode);
  
      return pixmap;
  }
  </code></pre>
  
  <p>This works very well if the QTreeview has already been seen by the user. The treeview appears in a tab in the main window. If the user see the treeview and then click the button that execute my above code, then all the treeview appears in the QPixmap. Otherwise only a bit of the treeview appears.</p>
  
  <p>Does anybody know how to solve this problem ?</p>
  
  <p>Thanks</p>