I want to preview, and then print, a report through a printer using PyQt. I tried the following code :
printer = QtGui.QPrinter()
doc = QtGui.QTextDocument("testing")
dialog = QtGui.QPrintDialog(printer)
dialog.setModal(True)
dialog.setWindowTitle("printerrr")
pdialog = QtGui.QPrintPreviewDialog(printer)
pdialog.setWindowFlags(QtCore.Qt.Window)
pdialog.exec_()
How I can preview my report then print it?
A PyQt5 update to the example by ekhumoro providing print preview and print for a Chart:
Edit: For the above demo code to run on Windows, then it requires:
Basic demo of Qt's print dialogs:
PyQt4
PyQt5
EDIT
To print-preview a graphics view, use its
render
method: