PDA

View Full Version : Print QWebView Error



brcontainer
1st June 2013, 16:26
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:
9094

Source:

QPrinter p;
p.setPaperSize(QPrinter::A4);
p.setFullPage(true);
p.setResolution(300);
p.setOrientation(QPrinter::Portrait);

QPrintPreviewDialog preview(&p);
preview.setWindowTitle(ui->myWebView->page()->mainFrame()->title());
connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(printPreview(QPrinter*)));
preview.exec();

...

void printPreview(QPrinter *printer) {
ui->myWebView->print(printer);
}


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

I also tried using this:

QPrinter p;
p.setPaperSize(QPrinter::A4);
p.setFullPage(true);
p.setResolution(300);
p.setOrientation(QPrinter::Portrait);

QPrintPreviewDialog preview(&p);
preview.setWindowTitle(ui->myWebView->page()->mainFrame()->title());
connect(&preview, SIGNAL(paintRequested(QPrinter*)), ui->myWebView, SLOT(print(QPrinter*)));
preview.exec();

But the error persists.

How to solve? Thanks.

ObiWanKenobe
29th September 2013, 13:37
I have the same problem.
It's a known issue: QTBUG-30621 (https://bugreports.qt-project.org/browse/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

ObiWanKenobe
1st October 2013, 22:05
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:


bool QPreviewPaintEngine::begin(QPaintDevice *)
{
Q_D(QPreviewPaintEngine);

qDeleteAll(d->pages);
d->pages.clear();

QPicture *page = new QPicture;
page->d_func()->in_memory_only = true;
d->painter = new QPainter(page);
d->engine = d->painter->paintEngine();
*d->painter->d_func()->state = *painter()->d_func()->state; // this line makes the difference
d->pages.append(page);
d->state = QPrinter::Active;
return true;
}


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

advseo32
9th October 2013, 18:31
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:


bool QPreviewPaintEngine::begin(QPaintDevice *)
{
Q_D(QPreviewPaintEngine);

qDeleteAll(d->pages);
d->pages.clear();

QPicture *page = new QPicture;
page->d_func()->in_memory_only = true;
d->painter = new QPainter(page);
d->engine = d->painter->paintEngine();
*d->painter->d_func()->state = *painter()->d_func()->state; // this line makes the difference
d->pages.append(page);
d->state = QPrinter::Active;
return true;
}


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 ?

ObiWanKenobe
9th October 2013, 18:43
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.:(

advseo32
9th October 2013, 20:20
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

9681

when i run in preview there is no problem

9682

how i can solve this problem ?

ObiWanKenobe
9th October 2013, 22:35
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


#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
...
#else
...
#endif

it's a relative simple task.

advseo32
10th October 2013, 08:23
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


#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
...
#else
...
#endif

it's a relative simple task.

where i can do this in .pro file ??

ObiWanKenobe
10th October 2013, 10:54
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:


#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtGui>
#else
#include <QtWidgets>
#endif

brcontainer
4th March 2014, 16:44
Error still exists in 5.2.1, see:
https://bugreports.qt-project.org/browse/QTBUG-37240

Vote please! Thanks!