How do I put an image in the PrinterPreviewDialog?
K9Developer opened this issue · 2 comments
K9Developer commented
how can i put a PIL image into the PrintPreviewDialog
892768447 commented
- convert PIL image to QPixmap
- get QPrintPreviewDialog
printer()
- maybe you can use QPainter on
printer
to draw pixmap
892768447 commented
like this:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter
from PyQt5.QtPrintSupport import QPrintPreviewDialog, QPrinter
from PyQt5.QtWidgets import QApplication
def drawImage(printer):
painter = QPainter()
painter.begin(printer)
painter.setPen(Qt.red)
painter.drawText(0, 0, 'hello PyQt5')
painter.end()
app = QApplication(sys.argv)
dlg = QPrintPreviewDialog()
dlg.printer().setOutputFormat(QPrinter.PdfFormat)
dlg.paintRequested.connect(drawImage)
dlg.exec_()
app.exec_()