Results 1 to 3 of 3

Thread: Printing WebEngine Pages

  1. #1
    Join Date
    Nov 2015
    Posts
    22
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Printing WebEngine Pages

    Hello,

    So it would appear that in Qt 5.6 printing for the web engine isn't as straight forward as I had hoped. I've not yet been able to locate an example of how this should be accomplished and was looking to see if anyone here could provide an example.

    Basically I'd like to invoke a preview of the page about to be presented so the end user can make adjustments, choose different printers, etc. and then print the page that is displayed in the current view of the web engine.

    I was able to get something to print using the following ( based on a few pieced together examples ), but it was very tiny on the page.

    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    2. QPainter painter;
    3. painter.begin(&printer);
    4. webEngineView->render(&painter);
    5. painter.end();
    To copy to clipboard, switch view to plain text mode 

    I didn't see anything obvious like a print function off the web view ( though that would be really nice ). I also did look at the QPrintPreviewDialogue, but wasn't sure how to incorporate it here.

    So if anyone has implemented printing in 5.6 for the web engine view as described above, an example would be helpful. Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Printing WebEngine Pages

    Print preview would work similar: basically if you put your lines 3-5 into a slot and call it from the place you have right now, you can also connect that slot to the print request signal of the preview dialog.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2015
    Posts
    22
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Printing WebEngine Pages

    Ok, so I put the following together based on you advice:

    Qt Code:
    1. void MainWindow::print(QPrinter* printer)
    2. {
    3. QPainter painter;
    4. painter.begin(printer);
    5. webEngineView->render(&painter);
    6. painter.end();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::printPreview()
    2. {
    3. QPrinter printer;
    4. QPrintPreviewDialog preview(&printer, this);
    5. connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(print(QPrinter*)));
    6. preview.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    When I call printPreview I do get the preview dialogue now and I can see the page ( though it is tiny, but I can work with the scaling issue later ), however after about 2 or 3 seconds the program crashes. Anything obvious I'm missing here?


    Added after 21 minutes:


    Never mind. This does work as expected, there was another, unrelated problem causing the crash.
    Last edited by brixel; 10th May 2016 at 12:03.

Similar Threads

  1. Qt WebEngine crashes after downloading
    By mentalmushroom in forum Qt Programming
    Replies: 0
    Last Post: 5th April 2016, 10:37
  2. Custom build - webengine libraries not copied to installation
    By Thomas233 in forum Installation and Deployment
    Replies: 1
    Last Post: 17th December 2015, 12:04
  3. Any kind of Web Inspector for WebEngine?
    By RolandHughes in forum Qt Programming
    Replies: 3
    Last Post: 1st July 2015, 22:56
  4. Replies: 2
    Last Post: 16th April 2014, 04:26
  5. I'm printing blank pages with QWebView
    By ihs280 in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2012, 17:43

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.