I can't wrap my mind around printing multiple pages using QPrintPreviewDialog. I searched the forum and the web, nothing helpful came up.
My goal is to print invoices, each page consists of a letter head at the top, followed by the details for the particular customer.
I have no trouble doing this for a single page but I wanted to get a preview with N invoices, each on a separate page.
Here is what I do now:
{
t.
append(QString("a nice letter head"));
t.append("\n");
t.
append(QString("customer info\n"));
t.append("\n\n\n\n\n\n______________________________________________________________\n"); //divider and some spacing
}
{
QPrintPreviewDialog pvw(printer,this);
if (bPreview)
connect(&pvw,
SIGNAL(paintRequested
(QPrinter *)),
SLOT(printPreview
(QPrinter *)));
prepHeader(pte); //show a company specific letter head
pte.append(detail);
if (bPreview)
{
pvw.exec();
pvw.disconnect();
pte.clear();
}
else
pte.print(printer);
}
void MainWindow
::printPreview(QPrinter *printer
) {
rpt.print(printer);
}
void MainWindow::printInvoice()
{
strm << "customer details" << endl;
printReport(rpt, detail, true);
detail.clear();
}
void MainWindow::prepHeader(QTextEdit &t)
{
t.append(QString("a nice letter head"));
t.append("\n");
t.append(QString("customer info\n"));
t.append("\n\n\n\n\n\n______________________________________________________________\n"); //divider and some spacing
}
void MainWindow::printReport(QTextEdit &pte, QString detail, bool bPreview)
{
QPrintPreviewDialog pvw(printer,this);
if (bPreview)
connect(&pvw, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *)));
prepHeader(pte); //show a company specific letter head
pte.append(detail);
if (bPreview)
{
pvw.exec();
pvw.disconnect();
pte.clear();
}
else
pte.print(printer);
}
void MainWindow::printPreview(QPrinter *printer)
{
rpt.print(printer);
}
void MainWindow::printInvoice()
{
QString detail;
QTextStream strm(&detail);
strm << "customer details" << endl;
printReport(rpt, detail, true);
detail.clear();
}
To copy to clipboard, switch view to plain text mode
Bookmarks