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 meth
I figured out my problem -- I was forgetting to delete the painter, which in hindsight seems obvious (doesn't it always?). Adding "del painter" to the end makes the code work. Here is working 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)
del painter