The migration from QWebKit
to QWebEngine
seems to be much more complicated than Qt guys claimed. With QWebKit I could print a webpage easily via
QWebView->print(&printer);
With QWebEngine
class QWebEngine
view does not provide a method print()
. Their browser example uses a class named QWebEngineFrame
which offers a method print()
- but the whole QWebEngineFrame
is not defined anywhere!
So my question: how do I print a page using QWebEngine
?
Qt 5.7 includes print support in to pdf files for QWebEngine.
Use printToPdf function to export the current page in a pdf file. Example:
I think the correct way to use
QWebEngineView::render
method becauseQWebEngineView
is aQWidget
. It accepts paint device as a first argument and you may passQPrinter
there for printing.Update: If you can use the latest version of Qt, in Qt 5.8 a new function for printing page was added:
Actually it first prints to temp PDF with
QPrinter
settings.Here is the link to Qt docs.
You can read about this in our blog also.
QWebView->page()->print(&printer, [=](bool){});
I would offer following code (for a while):