void PrintableWorksheet::initMembers()
{
page = new QWebEnginePage();
layout = new QPageLayout(QPageSize(QPageSize::A4),QPageLayout::Landscape, QMarginsF());
// The page loads html asynchronously, so we have to wait for loadFinished before printing
connect(page, SIGNAL(loadFinished(bool)), this, SLOT(printPageToPdf(bool)));
}
void PrintableWorksheet::printFile()
{
// html is a QString created in separate function
page->setHtml(qstring_of_html);
}
void PrintableWorksheet::printPageToPdf(bool ok)
{
if (ok) {
page->printToPdf(file_path, *layout); // file_path is set in separate function
} else {
"ERROR",
"Error: the pdf failed to load properly.");
error_box.exec();
}
}
// In ReceivingLogWidget class, the PrintableWorksheet object is created and used and a QFileSystemWatcher looks for when the pdf is generated
connect(file_watcher,
SIGNAL(directoryChanged
(QString)),
this,
SLOT(openPrintedPage
(QString)));
QString file_path
= QDir::homePath()+"/Desktop/Backstock_Worksheets";
PrintableWorksheet worksheet;
worksheet->setFilePath(file_path, file_name);
file_watcher->addPath(file_path);
worksheet->printFile();
void ReceivingLogWidget
::openPrintedPage(QString path
) {
Q_UNUSED(path);
QUrl url_of_file
= QUrl::fromLocalFile(worksheet
->getFilePath
());
}
void PrintableWorksheet::initMembers()
{
page = new QWebEnginePage();
layout = new QPageLayout(QPageSize(QPageSize::A4),QPageLayout::Landscape, QMarginsF());
// The page loads html asynchronously, so we have to wait for loadFinished before printing
connect(page, SIGNAL(loadFinished(bool)), this, SLOT(printPageToPdf(bool)));
}
void PrintableWorksheet::printFile()
{
// html is a QString created in separate function
page->setHtml(qstring_of_html);
}
void PrintableWorksheet::printPageToPdf(bool ok)
{
if (ok) {
page->printToPdf(file_path, *layout); // file_path is set in separate function
} else {
QMessageBox error_box(QMessageBox::Critical,
"ERROR",
"Error: the pdf failed to load properly.");
error_box.exec();
}
}
// In ReceivingLogWidget class, the PrintableWorksheet object is created and used and a QFileSystemWatcher looks for when the pdf is generated
QFileSystemWatcher *file_watcher = new QFileSystemWatcher();
connect(file_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(openPrintedPage(QString)));
QString file_path = QDir::homePath()+"/Desktop/Backstock_Worksheets";
PrintableWorksheet worksheet;
worksheet->setFilePath(file_path, file_name);
file_watcher->addPath(file_path);
worksheet->printFile();
void ReceivingLogWidget::openPrintedPage(QString path)
{
Q_UNUSED(path);
QUrl url_of_file = QUrl::fromLocalFile(worksheet->getFilePath());
QDesktopServices::openUrl(url_of_file);
}
To copy to clipboard, switch view to plain text mode
Bookmarks