J. Martin
J. Martin

Reputation: 1737

QtWebkit: Printing issue: no images on printed page

I have a webkit widget in my app and you can print it. It prints out fine, except there are no images when it prints, even though there are images on the screen.

Here is the code for printing:

void MainWindow::printPage() {
    QPrinter printer;
    printer.setPageSize(QPrinter::A4);
    printer.setPageMargins(10, 10, 10, 10, QPrinter::Millimeter);
    printer.setColorMode(QPrinter::Color);
    QPrintDialog* dialog = new QPrintDialog(&printer, this);
    if (dialog->exec() == QDialog::Accepted)
    {
         this->webView->page()->mainFrame()->print(&printer);
    }
}

I it also more or less ignores setting to A4 and defaults to letter, so I have to change it in the printer dialog popup, otherwise I have to futs with the printer buttons to force the print. Either way, it all comes out wrong...

Anyone have any pointers that might help me out? I am sure I am just missing something simple.

/Jason

Upvotes: 1

Views: 824

Answers (1)

Silas Parker
Silas Parker

Reputation: 8147

Try setting the QWebSettings::PrintElementBackgrounds attribute to true before printing:

QWebSettings::globalSettings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);

You could also set this on the QWebView specific settings, QWebView::settings()

Upvotes: 2

Related Questions