英文引用网址: https://www3.sra.co.jp/qt/relation/doc/qtwebengine/qtwebengine-webenginewidgets-printme-example.html
做个纪录,以便以后参考:
In the main function, we first instantiate a QWebEngineView and set the URL to our internal HTML page. Next, we create a PrintHandler instance and pass the requested page. For convenience, we also create keyboard shortcuts that can be used to call a print dialog or print preview dialog.
QWebEngineView view;
view.setUrl(QUrl(QStringLiteral("qrc:/index.html")));
view.resize(1024, 750);
view.show();
PrintHandler handler;
handler.setPage(view.page());
auto printPreviewShortCut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_P), &view);
auto printShortCut = new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_P), &view);
QObject::connect(printPreviewShortCut, &QShortcut::activated, &handler,