[Development] QWebEngineView Print

Kevin Kofler kevin.kofler at chello.at
Fri Jul 14 12:50:45 CEST 2017


Sudhir Sharma wrote:
> How can we print html loaded in QWebEngineView in QT 5.7?

In 5.7, you can only print by first printing to PDF and then invoking
something external to actually send the PDF to a printer. See the code
(submitted by me) in QupZilla 2.1.x (and currently also in master/2.2, but
since that requires Qt 5.8, it may be ported to the direct print method
soon, I've been wanting to look into that for a while). But that code
assumes the lpr executable is available on *nix, and there is an
implementation for Windows that is rather suboptimal (invokes the configured
PDF viewer and asks it to print).

You may want to upgrade to 5.8 or 5.9, where you just have to invoke the
print method.

It is also possible to upgrade QtWebEngine to 5.8 or 5.9 while keeping Qt
5.7, you will just need this one-line fix:

http://pkgs.fedoraproject.org/cgit/rpms/qt5-qtwebengine.git/plain/qtwebengine-opensource-src-5.8.0-qt57.patch

and you may want to explicitly enable spellchecking, which is disabled by
default when building against Qt 5.7:

WEBENGINE_CONFIG+=use_spellchecker

and if you are using CMake, you will likely also need this tweak on the
installed QtWebEngineConfig*.cmake files:

sed -i -e "s|%{version} \${_Qt5WebEngine|%{_qt5_version} \${_Qt5WebEngine|" \
  %{buildroot}%{_qt5_libdir}/cmake/Qt5WebEngine*/Qt5WebEngine*Config.cmake

QtWebEngine is the only part that of Qt you need to upgrade to get the print
method.

        Kevin Kofler




More information about the Development mailing list