title: Error printing image in PyQt
body: <p>I'm trying to print a widget in PyQt, but am getting the error that "QPaintDevice: Cannot destroy paint device that is being painted". I think the problem is that my method ends, and therefore the qPaintDevice is destroyed, before the painter has finished drawing the pixmap. I have no idea how to slow the painter down, however.</p>
  
  <p>The code for my method is here:</p>
  
  <pre><code>def printer(self):
      "Prints the current diagram"
      # Create the printer
      printerobject = QtGui.QPrinter(0)
      # Set the settings
      printdialog = QtGui.QPrintDialog(printerobject)
      if printdialog.exec_() == QtGui.QDialog.Accepted:
          # Print
          pixmapImage = QtGui.QPixmap.grabWidget(self.contentswidget)
          painter = QtGui.QPainter(printerobject)
          painter.drawPixmap(0, 0, pixmapImage)
  </code></pre>
  
  <p>For what it's worth, I tried using the .begin() and .end() approach, to no avail.</p>