Results 1 to 10 of 10

Thread: Print QWebView Error

  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

  6. #6
    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
    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.

    and what should i do ? to print it correctly in the paper ??


    Added after 1 1:


    is there any other solution to print report, because my project stopped now


    Added after 22 minutes:


    after printing i get an error

    this the how looks like the image

    c53w.png

    when i run in preview there is no problem

    previewPrint.png

    how i can solve this problem ?
    Last edited by advseo32; 9th October 2013 at 20:20.

  7. #7
    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 said, I have the same problem.
    Either you wait until 5.2 is out, or you port your program to 4.8.5 as I did.
    With a few

    Qt Code:
    1. #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    2. ...
    3. #else
    4. ...
    5. #endif
    To copy to clipboard, switch view to plain text mode 
    it's a relative simple task.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein

  8. #8
    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
    As I said, I have the same problem.
    Either you wait until 5.2 is out, or you port your program to 4.8.5 as I did.
    With a few

    Qt Code:
    1. #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    2. ...
    3. #else
    4. ...
    5. #endif
    To copy to clipboard, switch view to plain text mode 
    it's a relative simple task.
    where i can do this in .pro file ??

  9. #9
    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

    It has nothing to do with the pro file.
    Install Qt 4.8.5 and compile your program against it.
    Use the "#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)" in your sources.
    It is neccessary, because the module structure has changed in Qt5.
    For example:

    Qt Code:
    1. #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    2. #include <QtGui>
    3. #else
    4. #include <QtWidgets>
    5. #endif
    To copy to clipboard, switch view to plain text mode 
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein

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

    Exclamation Re: Print QWebView Error

    Error still exists in 5.2.1, see:
    https://bugreports.qt-project.org/browse/QTBUG-37240

    Vote please! Thanks!

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.