Results 1 to 10 of 10

Thread: Print QWebView Error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Posts
    65
    Thanks
    4
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question Print QWebView Error

    The first page of the print out of a QWebView with small fonts and images.

    Note: The error occurs in "windows 7" (not tested on other platforms)
    Note: Qt5.0.2, Windows 7 64bit
    The other pages are normal view a ScreenShot error:
    TXCp8.jpg

    Source:
    Qt Code:
    1. p.setPaperSize(QPrinter::A4);
    2. p.setFullPage(true);
    3. p.setResolution(300);
    4. p.setOrientation(QPrinter::Portrait);
    5.  
    6. QPrintPreviewDialog preview(&p);
    7. preview.setWindowTitle(ui->myWebView->page()->mainFrame()->title());
    8. connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(printPreview(QPrinter*)));
    9. preview.exec();
    10.  
    11. ...
    12.  
    13. void printPreview(QPrinter *printer) {
    14. ui->myWebView->print(printer);
    15. }
    To copy to clipboard, switch view to plain text mode 


    I used QPageSetupDialog and corrected in QPrintPreviewDialog but when printing on paper the error happens again.

    I also tried using this:
    Qt Code:
    1. p.setPaperSize(QPrinter::A4);
    2. p.setFullPage(true);
    3. p.setResolution(300);
    4. p.setOrientation(QPrinter::Portrait);
    5.  
    6. QPrintPreviewDialog preview(&p);
    7. preview.setWindowTitle(ui->myWebView->page()->mainFrame()->title());
    8. connect(&preview, SIGNAL(paintRequested(QPrinter*)), ui->myWebView, SLOT(print(QPrinter*)));
    9. preview.exec();
    To copy to clipboard, switch view to plain text mode 

    But the error persists.

    How to solve? Thanks.

  2. #2
    Join Date
    Oct 2011
    Location
    Germany
    Posts
    27
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Print QWebView Error

    I have the same problem.
    It's a known issue: QTBUG-30621
    It's commented, that it's done, but it isn't.
    I'm using Qt 5.1 (win7 x32, x64) and the contents of <TABLE> tags are displaced in the print preview.
    Can anybody tell, whether it's solved on Qt 5.1.1?

    Thanks
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein

  3. #3
    Join Date
    Oct 2011
    Location
    Germany
    Posts
    27
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Print QWebView Error

    Qt 5.2 alpha has the solution:
    just change the method bool QPreviewPaintEngine::begin(QPaintDevice *) in /qtbase/src/printsupport/kernel/qpaintengine_preview.cpp like this:

    Qt Code:
    1. bool QPreviewPaintEngine::begin(QPaintDevice *)
    2. {
    3. Q_D(QPreviewPaintEngine);
    4.  
    5. qDeleteAll(d->pages);
    6. d->pages.clear();
    7.  
    8. QPicture *page = new QPicture;
    9. page->d_func()->in_memory_only = true;
    10. d->painter = new QPainter(page);
    11. d->engine = d->painter->paintEngine();
    12. *d->painter->d_func()->state = *painter()->d_func()->state; // this line makes the difference
    13. d->pages.append(page);
    14. d->state = QPrinter::Active;
    15. return true;
    16. }
    To copy to clipboard, switch view to plain text mode 

    compile printsupport.pro...
    voilà ...
    it works.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein

  4. #4
    Join Date
    Jul 2013
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Print QWebView Error

    Quote Originally Posted by ObiWanKenobe View Post
    Qt 5.2 alpha has the solution:
    just change the method bool QPreviewPaintEngine::begin(QPaintDevice *) in /qtbase/src/printsupport/kernel/qpaintengine_preview.cpp like this:

    Qt Code:
    1. bool QPreviewPaintEngine::begin(QPaintDevice *)
    2. {
    3. Q_D(QPreviewPaintEngine);
    4.  
    5. qDeleteAll(d->pages);
    6. d->pages.clear();
    7.  
    8. QPicture *page = new QPicture;
    9. page->d_func()->in_memory_only = true;
    10. d->painter = new QPainter(page);
    11. d->engine = d->painter->paintEngine();
    12. *d->painter->d_func()->state = *painter()->d_func()->state; // this line makes the difference
    13. d->pages.append(page);
    14. d->state = QPrinter::Active;
    15. return true;
    16. }
    To copy to clipboard, switch view to plain text mode 

    compile printsupport.pro...
    voilà ...
    it works.

    i have modified the file and open the printsupport.pro in qtcreator , after that i have compile it

    but he generate no thing , what should he generate ? a .dll file ?

  5. #5
    Join Date
    Oct 2011
    Location
    Germany
    Posts
    27
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Print QWebView Error

    As I compiled the printsupport.pro, the output files were created in c:\lib.
    Copy the dll into qtdir/bin and lib file into qtdir/lib.

    The patch fixes the print preview, but the print out on the paper is still wrong.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein

Similar Threads

  1. QWebView: print problems
    By qks1 in forum Qt Programming
    Replies: 0
    Last Post: 26th March 2013, 10:01
  2. Print is Not working by using QWebView
    By swarajbindu in forum Qt Programming
    Replies: 0
    Last Post: 21st January 2013, 11:50
  3. Print a QWebView many times
    By Eddyc in forum Qt Programming
    Replies: 0
    Last Post: 28th August 2012, 11:37
  4. QWebView print to PDF and add background image
    By supergillis in forum Qt Programming
    Replies: 0
    Last Post: 9th September 2010, 14:02
  5. QWebView print() not printing as WYSIWYG
    By thiagoalencar22 in forum Qt Programming
    Replies: 1
    Last Post: 4th November 2009, 13:43

Tags for this Thread

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.