I need to know what code Qt requires to allow QWebEnginePage::printToPdf()
to proceed to actually print the PDF?
Through necessity rather than choice, I need to await completion of the printing to file before my code can continue, i.e. effectively I need a synchronous printToPdf()
.
The outline of my code (PyQt5, QT 5.7) is:
def synchronousPrintToPdf(self):
self.webView.page().printToPdf(self.callbackPrintToPdf)
# allow printing to proceed - what to put here??
# wait for callbackPrintToPdf() to complete
def callbackPrintToPdf(self, data: QByteArray):
# save data to some output file
# signify that printing has completed,
# so that synchronousPrintToPdf() can exit
The problem is not the behaviour of callbackPrintToPdf()
--- if & when the printing proceeds it gets called and executes fine. Rather the issue is what QWebEnginePage::printToPdf()
requires the calling code to do in order to allow it to actually proceed to do the printing.
I have found that if the caller happens to put up a (modal) dialog after calling synchronousPrintToPdf()
then at that point the printing proceeds and callbackPrintToPdf()
gets executed.
I need to know what the caller can do without a dialog (or any other interaction)? Stumbling around a bit, I have tried (in synchronousPrintToPdf()
):
self.printLoop = QEventLoop(self)
self.printLoop.exec()
However, this does not cause the printing to proceed.
I believe that after calling QWebEnginePage::printToPdf()
the actual printing is done in a separate thread. What is it about putting up a dialog (QtWidgets.QDialog.open()
) that allows this to execute so that I can use some part of it without actually waiting for interaction?