Results 1 to 2 of 2

Thread: printing QWebView before showing in Dialog

  1. #1
    Join Date
    Jun 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default printing QWebView before showing in Dialog

    Hi,

    I'm trying to print a QWebview before it is showed in the Dialog
    Qt Code:
    1. QString html = getHtmlString(); // Get the HTML String
    2. ui.webView->setHtml(html); // set the Html string to the QWebView
    3.  
    4. QPrinter printer; // Create the Printer
    5. printer.setOutputFormat(QPrinter::PdfFormat);
    6. printer.setPageSize(QPrinter::A4);
    7. printer.setOrientation(QPrinter::Landscape);
    8.  
    9. QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),QCoreApplication::applicationDirPath(),tr("*.pdf"));
    10. if(fileName.length()>0 ){
    11. printer.setOutputFileName(fileName);
    12. ui.webView->print(&printer); // print the QWebview
    13. QDesktopServices::openUrl(QUrl(fileName));
    14. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Apr 2008
    Location
    Michigan
    Posts
    6
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: printing QWebView before showing in Dialog

    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?).

Similar Threads

  1. QWebview not showing images
    By manojmka in forum Qt Programming
    Replies: 27
    Last Post: 17th July 2012, 00:22
  2. Showing a dialog at application startup
    By PaladinOfKaos in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2008, 21:05
  3. [QT4] Printing a dialog
    By KShots in forum Qt Programming
    Replies: 13
    Last Post: 28th April 2006, 14:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.