1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| class PrintSuiviFP(QPrintPreviewDialog):
def __init__(self, parent, grid1, grid2, grid3, grid4, df1, df2, mois, annee):
super().__init__()
self.parent = parent
self.grid1 = grid1
self.grid2 = grid2
self.grid3 = grid3
self.grid4 = grid4
self.mois = mois
self.annee = annee
self.df1 = df1
self.df2 = df2
self.dialog = QPrintPreviewDialog()
self.document = QTextDocument()
self.cursor = QTextCursor(self.document)
self.block_format = self.cursor.blockFormat()
def preview(self):
self.dialog.setModal(True)
self.dialog.paintRequested.connect(self._handle_paint_request)
self.dialog.showMaximized()
self.dialog.exec()
def _handle_paint_request(self, printer):
self.document.setDefaultFont(QFont('Calibri', 11))
self.block_format.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.cursor.setBlockFormat(self.block_format)
header_text = "TITRE"
self.cursor.insertBlock()
self.cursor.insertText(header_text, self._format_header())
self.cursor.insertBlock()
self.cursor.insertText(' ', self._format_header())
self.cursor.insertBlock()
self._build_left_block() # construction de la partie gauche de mon QTextDocument
self._build_right_block() # construction de la partie droite de mon QTextDocument
printer.setPageOrientation(QPageLayout.Orientation.Landscape)
self.document.setPageSize(QSizeF(1210, 800))
self.document.setDocumentMargin(1)
self.document.print(printer) |
Partager