Am trying to follow the documentation for printing a QWidet and am getting an error. When I run the following code I get QPaintDevice: Cannot destroy paint device that
QPainter for optimization does not apply all the tasks at the same time but it keeps instructions and applies them at the end but to force that task it is better to call the end() method or delete with it since the destroyer also calls end(), in addition it is not necessary for QPainter to be a member of the class:
def print_me(self):
printer = QtGui.QPrinter()
printer.setOutputFormat(QtGui.QPrinter.PdfFormat)
printer.setOutputFileName("Test.pdf")
painter = QtGui.QPainter(printer)
xscale = printer.pageRect().width() / self.width()
yscale = printer.pageRect().height() / self.height()
scale = min(xscale, yscale)
painter.translate(printer.paperRect().center())
painter.scale(scale, scale)
painter.translate((self.width() / 2) * -1, (self.height() / 2) * -1)
self.render(painter)
painter.end()
# or
# del painter