QPrinter & QPainter render() problem
-
I have a problem when calling Qwidget::render() on a specific printer connected via a network to a PC running XP. I am quite new to using the Qprinter class so I apologise if I am missing something obvious. I get a repeatable crash when rendering to the printer in question. The only diffreence I can see between the working printers and the crashing one is the printer resolution. I seem to get the problem no matter what I render. The crash always seesm to occur at the render() call.
Here is attached example code:
@
void MainWindow::menuPrintTest(){
double xscale; double yscale; double scale;
double printerWidth ; double printerHeight ;
double widgetWidth; double widgetHeight ;
QFont printFont("courier", 16);
printFont.setFixedPitch(TRUE);
QTextEdit *qteTestPrintRequest = new QTextEdit("",w);
qteTestPrintRequest ->setFont(printFont );
qteTestPrintRequest ->setFixedHeight(1750);
qteTestPrintRequest ->setFixedWidth(1050);
widgetWidth = qteTestPrintRequest ->width();
widgetHeight = qteTestPrintRequest ->height();QString qsConcat = "Test Printout For Checking XP Print Request Bug\n"; for (int i=0; i<30; i++){ qsConcat+= "Test Printout for Checking XP Print Request Bug\n" ; } qteTestPrintRequest->append( qsConcat ); QPrinter printer(QPrinter::HighResolution); QString docName = "Test Plot"; if ( !docName.isEmpty()) { docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- ")); printer.setDocName (docName); } QPrintDialog dialog(&printer); if ( dialog.exec() ) { { { QPainter painter(&printer); printerWidth = printer.pageRect().width(); printerHeight = printer.pageRect().height(); xscale = printerWidth/(widgetWidth); yscale = printerHeight/(widgetHeight); scale = qMin(xscale, yscale); painter.scale(scale, scale); qteTestPrintRequest ->render(&painter); } } }
}
@The qDebug() output for the scaling is as follows:
printerWidth = 4908.0
printerHeight = 6408.0
widgetWidth = 1050.0
widgetHeight = 1750.0
xscale = 4.674
yscale = 3.662
scale = 3.662As a matter of interest the output on one of the working printers is
printerWidth = 4760.0
printerHeight = 6814.0
widgetWidth = 1050.0
widgetHeight = 1750.0
xscale = 4.533
yscale = 3.894
scale = 3.894 -
I don't want to duplicate effort. My great thanks to all who have helped so far.
"I hope that this is helpful to all concerned but this thread is being discussed in more detail on this link.":http://www.qtforum.org/article/37518/qprinter-qpainter-render-problem.html#post117656
-
"I do need to rsolve this ASAP and would be willing to pay for a solution/resolution.":http://www.qtforum.org/article/37518/qprinter-qpainter-render-problem.html#post117656
The code above seems to work perfectly with all other configurations of Printer & PC tested. The problem seems to be that my simple test printout is generating a huge print document approximately a factor of 4000 times bigger (e.g. 213MB for a single A4 sheet) when sent to the specific printer involved:
Xerox Work Centre 7428 PS
The only potential leads I have are that it may be due to
-
A specific printer driver issue
-
QPrinter printer(QPrinter::HighResolution);
A guess. -
qteTestPrintRequest->render(&painter);
Using render with a QTextEdit widget instead of using qteTestPrintRequest ->print(&printer); -
Some other unidentified issue with the code posted above?
-
-
I can see now in hindsight that my URGENT capitals may have come across in the wrong way. I was not intending to shout about anything other than my offer of payment. It was not in any way impatience. I can see that it seems out of context without the preceding posts on the linked to forum.
I apologise for the confusion and potential offence that my clumsy post may have caused (Embarrassed smiley!)