How do you print QWebEngineView content in PyQt6?
-
Currently developing an app for managing stores, and the app makes an invoice or receipt of items sold for example, so ideally made that invoice with the help of Jinja template (populated with those items fetched from db), then because of limitations of QTextDocument at rendering html (which I managed to overcome at first in my case, but then the font size of document keeps changing from pc to pc with same code, and couldn't handle that issue or solve it), I decided to go for QWebEngineView and made it work, but now when it comes to printing it, I simply couldn't find ANY POSSIBLE way to do so, whether by .printToPdf then create a QPdfDocument, or even go beyound that with QPdfView, since unfortunately the print() method that used to be on QWebEngineView.page() is depracated in the recent versions of qt and internet is only full of that solution (even the qt example shows only that way here), so how do you handle printing the content of QWebEngineView in these recent versions or do you recommend another entire approach for this and THANK YOU!
-
Currently developing an app for managing stores, and the app makes an invoice or receipt of items sold for example, so ideally made that invoice with the help of Jinja template (populated with those items fetched from db), then because of limitations of QTextDocument at rendering html (which I managed to overcome at first in my case, but then the font size of document keeps changing from pc to pc with same code, and couldn't handle that issue or solve it), I decided to go for QWebEngineView and made it work, but now when it comes to printing it, I simply couldn't find ANY POSSIBLE way to do so, whether by .printToPdf then create a QPdfDocument, or even go beyound that with QPdfView, since unfortunately the print() method that used to be on QWebEngineView.page() is depracated in the recent versions of qt and internet is only full of that solution (even the qt example shows only that way here), so how do you handle printing the content of QWebEngineView in these recent versions or do you recommend another entire approach for this and THANK YOU!
@rida_zouga
Not my area, but are you aware thatQWebEngineView, rather thanQWebEnginePage, still has void QWebEngineView::print(QPrinter *printer)? All printing seems to go via one of theprintToPdf()methods. -
Oh yes sorry my bad, the print method eventually still exists for the QWebEngineView in the recent versions too, again sorry and thank you so much for your help.
-
R rida_zouga has marked this topic as solved
-
Oh yes sorry my bad, the print method eventually still exists for the QWebEngineView in the recent versions too, again sorry and thank you so much for your help.
@rida_zouga
Sorry, yes, I forgot you said Python. I just search/post links from C++ reference pages.https://doc.qt.io/qt-6/qtwebengine-changes-qt6.html#qwebenginepage
QWebEnginePage
Has been moved to Core, and API that worked on QWebEngineView or QPrinter has been moved, and can now be accessed only from QWebEngineView. See Changed API.