See if that helps anything.
import sys
from PyQt5.QtPrintSupport import QPrintDialog, QPrinter, QPrintPreviewDialog
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QTextEdit, QToolTip, QVBoxLayout, QHBoxLayout
class Window(QWidget):
def __init__(self, **ac):
super( ).__init__(**ac)
self.vbox = QVBoxLayout( )
self.title = "Cadastro"
self.top = 100
self.left = 100
self.width = 640
self.height = 480
self.setWindowIcon(QtGui.QIcon("img1.png"))
self.setLayout(self.vbox)
self.InitWindow( )
def InitWindow(self):
self.hbox = QHBoxLayout( )
self.print_btn = QPushButton("IMPRIMIR", self)
self.print_btn.clicked.connect(self.print)
self.view_btn = QPushButton("VISUALIZAR", self)
self.view_btn.clicked.connect(self.view)
self.edt = QTextEdit(self)
self.vbox.addWidget(self.edt)
self.hbox.addWidget(self.print_btn)
self.hbox.addWidget(self.view_btn)
self.vbox.addLayout(self.hbox)
self.setWindowTitle(self.title)
self.setGeometry(self.top, self.left, self.width, self.height)
self.show( )
def print(self):
prt = QPrinter(QPrinter.HighResolution)
dialog = QPrintDialog(prt)
if dialog.exec_( ) == QPrintDialog.Accepted:
self.edt.print_(prt)
def view(self):
pt = QPrinter(QPrinter.HighResolution)
prev = QPrintPreviewDialog(pt, self)
prev.paintRequested.connect(self.preview)
prev.exec_( )
def preview(self, pt):
self.edt.print_(pt)
App = QApplication(sys.argv)
window = Window( )
sys.exit(App.exec_( ))
Use a
QPainter
, then you draw on it and then print– nosklo