Printer.py 450 B

1234567891011121314
  1. from PySide6.QtWidgets import QTextEdit, QDialog
  2. from PySide6.QtPrintSupport import QPrintDialog, QPrinter
  3. class Printer:
  4. def __init__(self, text: str) -> None:
  5. self.printer = QPrinter()
  6. self.editor = QTextEdit()
  7. self.editor.setHtml(text)
  8. def print(self) -> None:
  9. dialog = QPrintDialog(self.printer)
  10. if dialog.exec_() == QDialog.Accepted:
  11. self.editor.document().print_(dialog.printer())