[PyQt] Printing in PyQt
primalcharlie
charlie.hardy at outlook.com
Fri Feb 20 19:31:10 GMT 2015
Hi Im hoping to print a whole screen and as a separate print a widget:
However I have no clue as to how to do it. I know that I need to do a paint
and paint to the printer and get the details using a QPrintDialog however
past that point my knowledge is limited. I found the following on the
internet in the pyqt docs but it isn't working
Charlie
def printViewCustomer(self):
printer=QtPrintSupport.QPrinter()
dialog=QtPrintSupport.QPrintDialog(printer,self)
if (dialog.exec_()!=QtWidgets.QDialog.Accepted):
return
printWidget=self.mainViewWidget
painter=QtGui.QPainter(printer)
painter.begin(printer)
print(printer.paperRect().x())
XScale=(printer.pageRect().width()/ (printWidget.width()))
YScale=(printer.pageRect().height()/(printWidget.height()))
Scale=(min(XScale,YScale))
painter.translate((printer.paperRect().x()) +
(printer.pageRect().width()/2),(printer.paperRect().y) +
(printer.pageRect().height()/2))
painter.scale(Scale,Scale)
painter.translate(-1*printWidget.width()/2,-1*printWidget.height()/2)
printWidget.render(painter)
painter.end()
--
View this message in context: http://python.6.x6.nabble.com/Printing-in-PyQt-tp5086981.html
Sent from the PyQt mailing list archive at Nabble.com.
More information about the PyQt
mailing list