Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Печать HTML-документа в Qt 5.8
#include <QDebug>
#include <QPrinter>
#include <QPrintDialog>
#include <QPrinterInfo>
#include <QWebEnginePage>
void MainWindow::on_printButton_clicked()
{
QPrinter * printer = new QPrinter();
QPrintDialog printDialog(printer, this);
if (printDialog.exec() != QDialog::Accepted) {
return;
}
QWebEnginePage * page = new QWebEnginePage;
page->setHtml("<html><body>Привет<body/></html>");
connect(page, &QWebEnginePage::loadFinished, [page, printer] (bool ok) {
if (!ok) {
qDebug() << "Загрузка документа провалилась.";
delete page;
delete printer;
return;
}
page->print(printer, [page, printer](bool ok) {
if (ok) {
qDebug() << "Документ напечатан.";
}
else {
qDebug() << "Печать документа провалилась.";
}
delete page;
delete printer;
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.