Skip to content

Instantly share code, notes, and snippets.

@ttldtor
Created March 19, 2014 10:33
Show Gist options
  • Save ttldtor/9639164 to your computer and use it in GitHub Desktop.
Save ttldtor/9639164 to your computer and use it in GitHub Desktop.
QWebView *MuWebView::createWindow(QWebPage::WebWindowType type) {
Q_UNUSED(type)
QWebView* webView = new QWebView;
QWebPage* webPage = new QWebPage(webView);
webView->setWindowModality(Qt::ApplicationModal);
webView->setAttribute(Qt::WA_DeleteOnClose, true);
webView->setPage(webPage);
connect(webPage, &QWebPage::printRequested, [&](QWebFrame *frame) {
if (!frame) {
return;
}
QPrintPreviewDialog* printPreviewDialog = new QPrintPreviewDialog();
connect(printPreviewDialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter* printer){
frame->print(printer);
});
printPreviewDialog->exec();
printPreviewDialog->disconnect();
printPreviewDialog->deleteLater();
});
webView->show();
return webView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment