May 2019
Intermediate to advanced
542 pages
13h 37m
English
Nobody likes to waste paper by printing something that isn't right, so we should add a print_preview function. QPrintPreviewDialog exists for this purpose and works very much like other printing dialogs, as follows:
def print_preview(self): dialog = qtps.QPrintPreviewDialog(self.printer, self) dialog.paintRequested.connect(self._print_document) dialog.exec() self._update_preview_size()
Once again, we just need to pass the printer object to the dialog's constructor and call exec(). We also need to connect the dialog's paintRequested signal to a slot that will update the document in QPrinter so that the dialog can make sure the preview is up to date. Here, we've connected it to our _print_document() method, which does exactly ...
Read now
Unlock full access