PDA

View Full Version : printing QWebView before showing in Dialog



Grisu
6th June 2008, 17:36
Hi,

I'm trying to print a QWebview before it is showed in the Dialog


QString html = getHtmlString(); // Get the HTML String
ui.webView->setHtml(html); // set the Html string to the QWebView

QPrinter printer; // Create the Printer
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPageSize(QPrinter::A4);
printer.setOrientation(QPrinter::Landscape);

QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),QCoreApplication::applicationDirPath(),tr("*.pdf"));
if(fileName.length()>0 ){
printer.setOutputFileName(fileName);
ui.webView->print(&printer); // print the QWebview
QDesktopServices::openUrl(QUrl(fileName));
}


The printed html pdf is always white.
If I print the webview by pressing a button after it has been shown on the Dialog there's text in the pdf.

Can anyone help me?

Thanks,

Grisu

jonman364
17th July 2008, 12:20
I am not certain about this because I was having the same problem. But I think you have to wait until after the QWebView::loadFinished() signal has been emitted. When you click the button, you probably have given it enough time to load (does it load after returning to the event loop?).