Reputation: 43
last year i converted html to pdf with pyqt4 succesfully.. but with pyqt5 i lost 2 days and i´m frustrated..
This is my code:
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKitWidgets import QWebView
from PyQt5.QtPrintSupport import QPrinter
from PyQt5.QtCore import QUrl
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("https://www.google.com"))
printer = QPrinter()
printer.setPageSize(QPrinter.A4)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName("out.pdf")
def convertIt():
web.print_(printer)
print ('Pdf generado')
QApplication.exit()
QObject.connect(web, SIGNAL("loadFinished(bool)"), convertIt)
app.exec_()
And i have one "QOject no have attribute "connect"... i know is something about the signals, that changed from pyqt4 to pyqt5, but i have no idea to code it.. thanks in advance.
Upvotes: 3
Views: 3130
Reputation: 11989
This should be web.loadFinished.connect(convertIt)
as per the PyQt docs about signals/slots.
Upvotes: 2