Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: QPrinter & QPainter render() problem

  1. #1
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default 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:

    Qt Code:
    1. void MainWindow::menuPrintTest(){
    2. double xscale; double yscale; double scale;
    3. double printerWidth ; double printerHeight ;
    4. double widgetWidth; double widgetHeight ;
    5. QFont printFont("courier", 16);
    6. printFont.setFixedPitch(TRUE);
    7. QTextEdit *qteTestPrintRequest = new QTextEdit("",w);
    8. qteTestPrintRequest ->setFont(printFont );
    9. qteTestPrintRequest ->setFixedHeight(1750);
    10. qteTestPrintRequest ->setFixedWidth(1050);
    11. widgetWidth = qteTestPrintRequest ->width();
    12. widgetHeight = qteTestPrintRequest ->height();
    13.  
    14. QString qsConcat = "Test Printout For Checking XP Print Request Bug\n";
    15. for (int i=0; i<30; i++){ qsConcat+= "Test Printout for Checking XP Print Request Bug\n" ; }
    16. qteTestPrintRequest->append( qsConcat );
    17.  
    18. QPrinter printer(QPrinter::HighResolution);
    19. QString docName = "Test Plot";
    20. if ( !docName.isEmpty()) {
    21. docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- "));
    22. printer.setDocName (docName);
    23. }
    24. QPrintDialog dialog(&printer);
    25. if ( dialog.exec() ) {
    26. {
    27. {
    28. QPainter painter(&printer);
    29. printerWidth = printer.pageRect().width();
    30. printerHeight = printer.pageRect().height();
    31. xscale = printerWidth/(widgetWidth);
    32. yscale = printerHeight/(widgetHeight);
    33. scale = qMin(xscale, yscale);
    34. painter.scale(scale, scale);
    35. qteTestPrintRequest ->render(&painter);
    36. }
    37. }
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 





    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.662

    As 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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPrinter & QPainter render() problem

    Try printing something small - does it still crash then?
    Also, you have a memory leak - you never delete 'qteTestPrintRequest' (but that should not play a role in the problem you have).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    Thankyou

    I will try a print that is well within the pageRect() dimensions.

  4. #4
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    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...tml#post117656

  5. #5
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    "I do need to rsolve this ASAP and would be willing to pay for a solution/resolution.":http://www.qtforum.org/article/37518...tml#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

    1. A specific printer driver issue

    2. QPrinter printer(QPrinter::HighResolution);
    A guess.

    3. qteTestPrintRequest->render(&painter);
    Using render with a QTextEdit widget instead of using qteTestPrintRequest ->print(&printer);

    4. Some other unidentified issue with the code posted above?
    Last edited by Mannion; 11th March 2012 at 20:47.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter & QPainter render() problem

    Maybe you should bother to answer high_flyer's question from post #2?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    Well I did on the link. I had assumed that those interested would follow it. I am genuinely sorry if that has been misleading or unhelpful.

    The scaling factor seemed to have no effect on the outcome even when I sent an image significantly within the pageRect bounds.

    The problem is not a crash but just that a huge file is generated on a particular printer (as stated in my last post). I have to the best of my knowledge identified the current status of the problem in summarised form. If I can clarify anything I would be very happy to do so. As always I am extremely grateful for any insight gleaned from those kind enough to help.

    The use of the link was merely a genuine, honest attempt to minimise the amount of work generated for those kind enough to help and to reduce any duplication. If you would prefer that I duplicate all that transpires on that link then I have no problem with that.

    Please advise. I am quite new to this forum.

    Thanks Again
    M

    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!)


    Added after 1 5 minutes:


    Capitals now editted.
    Last edited by Mannion; 11th March 2012 at 20:49.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter & QPainter render() problem

    So does printing a smaller document and/or in a smaller resolution help or not? I read the thread behind the link twice and I didn't see the answer to this question.

    Also what happens if you print to PDF instead of to the printer? How large is the file generated?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    Mannion (11th March 2012)

  10. #9
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    OK my apologies when re reading the thread it is less clear than I had thought but in the summary conclusions and in the context of my original, incorrectly posted crash query there was no crash caused by the resolution. If you are asking if the extreme print document size might be caused specifically by the dimensions of the rendered widget then that is another and interesting matter. In my last post I stated that the scaling factor seemed to have no effect on the huge print document phenomenon (that is other than a proportional change in its size).

    I did not have the chance to test specifying a different a resolution setting in my rare opportunity on site as there were problems with drivers on site and security & IT etc.

    Thankyou for your PDF output idea. I will test and respond. Currently the problem only happens specifically when outputting to the Xerox Work Centre 7428 PS printer.

    Thanks again M

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter & QPainter render() problem

    Quote Originally Posted by Mannion View Post
    Thankyou for your PDF output idea. I will test and respond. Currently the problem only happens specifically when outputting to the Xerox Work Centre 7428 PS printer.
    The point is to see how large the document is when still in postscript format. Apparently later the printer driver rasterizes the document which inflates its size. How much memory does the printer have?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #11
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    Well even though it can print ok directly to my test printer when using:
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    To copy to clipboard, switch view to plain text mode 
    the test application does seem to generate quite a large pdf weighing in at 4,164 KB for a single page single image renderred widget. This is, however, not in the same league as the Xerox prints which are over 50 times larger. I'm not sure how significant this is as it is my first attempt at any form of Qt PDF file generation.

    I ran a test with
    Qt Code:
    1. QPrinter printer(QPrinter::ScreenResolution);
    To copy to clipboard, switch view to plain text mode 
    and it produced a file of 197KB.

    Likewise with
    Qt Code:
    1. QPrinter printer(QPrinter::PrinterResolution);
    To copy to clipboard, switch view to plain text mode 
    the file size produced was 131KB

    To my untrained eyes this seems quite a significant difference is that what is expected in terms of resolution quality?

    I have attached the rapidly thrown together demo code and I apologise for any potentially obvious mistakes. I shall continue testing different parameters.

    Qt Code:
    1. void MainWindow::menuPrintTest(){
    2. double xscale; double yscale; double scale; double printerWidth ; double printerHeight ; double widgetWidth; double widgetHeight ;
    3.  
    4. QFont printFont("courier", 16);
    5. printFont.setFixedPitch(TRUE);
    6. QTextEdit *qteTestPrintRequest = new QTextEdit("",w);
    7. qteTestPrintRequest ->setFont(printFont );
    8. qteTestPrintRequest ->setFixedHeight(500); //NEW
    9. qteTestPrintRequest ->setFixedWidth(750); //NEW
    10. widgetWidth = qteTestPrintRequest ->width() ; //+200; //NEW MOD
    11. widgetHeight = qteTestPrintRequest ->height() ; //+300; //NEW MOD
    12. QString qsConcat = "Test Printout For Checking XP Print Request Bug\n";
    13. for (int i=0; i<30; i++){ qsConcat+= "Test Printout for Checking XP Print Request Bug\n" ; }
    14. qteTestPrintRequest->append( qsConcat );
    15.  
    16. QPrinter printer(QPrinter::HighResolution);
    17. printer.setOutputFormat(QPrinter::PdfFormat); //PDF ADD
    18. printer.setOutputFileName("Test.pdf"); //PDF ADD
    19.  
    20. QString docName = "Test Plot";
    21. if ( !docName.isEmpty()) {
    22. docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- "));
    23. printer.setDocName (docName);
    24. }
    25. //QPrintDialog dialog(&printer); //PDF REMOVE
    26. //if ( dialog.exec() ) { //PDF REMOVE
    27. {
    28. QPainter painter;
    29. painter.begin(&printer);
    30. printerWidth = printer.pageRect().width();
    31. printerHeight = printer.pageRect().height();
    32. xscale = printerWidth/(widgetWidth);
    33. yscale = printerHeight/(widgetHeight);
    34. scale = qMin(xscale, yscale);
    35. painter.scale(scale, scale);
    36. qteTestPrintRequest ->render(&painter); //qteTestPrintRequest->print(&printer);
    37. painter.end();
    38. } //QPAINTER CTOR BRACE
    39. }
    40. //}else{} //PDF REMOVE
    41. delete qteTestPrintRequest;
    42. }
    To copy to clipboard, switch view to plain text mode 


    Added after 4 minutes:


    Changing the size of the renderred QTextEdit widget seems to only change the file size proportionally.

    http://doc.qt.nokia.com/4.7-snapshot...interMode-enum
    States that for QPrinter::PrinterResolution
    This value is deprecated. Is is equivalent to ScreenResolution on Unix and HighResolution on Windows and Mac. Due do the difference between ScreenResolution and HighResolution, use of this value may lead to non-portable printer code.
    and for QPrinter::HighResolution
    On Windows, sets the printer resolution to that defined for the printer in use. For PostScript printing, sets the resolution of the PostScript driver to 1200 dpi.
    If it weren't for this I would be looking at substituting QPrinter::PrinterResolution for QPrinter::HighResolution.

    Still my big question is if it is ok to use QTextEdit->render(&painter)




    In response to your post:

    The point is to see how large the document is when still in postscript format. Apparently later the printer driver rasterizes the document which inflates its size. How much memory does the printer have?
    The printer still manages to print the document it just takes a long time to send the data to the printer. In the test the 213MB was the size observed in the printer document queue on the PC running the test app.

    It is a fairly modern, high spec printer serving a large-ish office. It must have a sizeable memory. All of the other printers tested were of a lower spec to the problem printer.
    Last edited by Mannion; 11th March 2012 at 22:13.

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter & QPainter render() problem

    Quote Originally Posted by Mannion View Post
    the test application does seem to generate quite a large pdf weighing in at 4,164 KB for a single page single image renderred widget.
    Hmmm... are you printing a widget or a document? What does the document contain?

    To my untrained eyes this seems quite a significant difference is that what is expected in terms of resolution quality?
    Yes, of course. Your screen has a resolution of around 100DPI, the printer's high resolution is probably around 1200DPI which means one page is 144 times larger.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #13
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    Hmmm... are you printing a widget or a document? What does the document contain?
    A widget as per the code, more specifically:

    Qt Code:
    1. QFont printFont("courier", 16);
    2. printFont.setFixedPitch(TRUE);
    3. QTextEdit *qteTestPrintRequest = new QTextEdit("",w);
    4. qteTestPrintRequest ->setFont(printFont );
    5. qteTestPrintRequest ->setFixedHeight(500); //NEW
    6. qteTestPrintRequest ->setFixedWidth(750); //NEW
    7. widgetWidth = qteTestPrintRequest ->width() ; //+200; //NEW MOD
    8. widgetHeight = qteTestPrintRequest ->height() ; //+300; //NEW MOD
    9. QString qsConcat = "Test Printout For Checking XP Print Request Bug\n";
    10. for (int i=0; i<30; i++){ qsConcat+= "Test Printout for Checking XP Print Request Bug\n" ; }
    11. qteTestPrintRequest->append( qsConcat );
    To copy to clipboard, switch view to plain text mode 

    Yes, of course. Your screen has a resolution of around 100DPI, the printer's high resolution is probably around 1200DPI which means one page is 144 times larger.
    Yes I agree that this point is redundant. However compression and the discrepancy between the Printer and High resolutions are not covered by this observation. Clearly something else is going on.


    Added after 16 minutes:


    After examining the PDF documents it seems as though the differences in PDF file size could be down to resolution and compression alone. The differences between HighResolution and PrinterResolution are a little less easy to explain. Perhaps they represent the difference between some lower printer resolution setting and the printer's high resolution setting. The resolution of the PrinterResolution PDF is quite low indeed.

    The only clear link to the Xerox problem that I can identify is that the Xerox would perhaps have the potential for a very high resolution upper setting. This could perhaps partially explain the factor of 4000 in the queued printer document size.

    Does this make any sense to you or am I barking up the wrong tree?

    It seems like this issue would probably crop up an awful lot if this is all that is happening. Is the QTextEdit->render() call part of the issue?

    Can I get high resolution scaled images without setting the highest available printer resolution?
    Last edited by Mannion; 11th March 2012 at 22:47.

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter & QPainter render() problem

    Quote Originally Posted by Mannion View Post
    A widget as per the code,
    Then you are printing an image, a bitmap, which is large per definition. Not that I see any point in printing a widget and not a document contained in it.

    Yes I agree that this point is redundant. However compression and the discrepancy between the Printer and High resolutions are not covered by this observation. Clearly something else is going on.
    I don't see anything "clear" here. You get a 200 MB printer job because you rasterize an image in high resolution. This just has to take time and memory.

    Can I get high resolution scaled images without setting the highest available printer resolution?
    If your image has 100 DPI then scaling it up to 1200 DPI doesn't make sense and you can print it in 100 DPI, the quality will be the same.

    But first think if you should really be printing the widget and not the document it contains (which would have much higher quality and much lower volume).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #15
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    There is no document to print unless you mean the .text property. All the text is added via append

    The widgets are renderred off screen. I got very poor results using the screen resolution setting


    Added after 6 minutes:


    The exact same renderring request ( in terms of code )produced a local queued printer document over 4000 times larger with the problem printer than with several printers of at least 600dpi
    Last edited by Mannion; 12th March 2012 at 02:22.

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter & QPainter render() problem

    Quote Originally Posted by Mannion View Post
    There is no document to print unless you mean the .text property.
    So... are you printing an empty QTextEdit widget? Are you aware of the distinction between QTextEdit and QTextDocument?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #17
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    There is no subterfuge here. I am doing exactly what is in the code at the very beginning of the thread. Nothing has changed. I'm not sure where the questions regarding what I am printing are coming from. If the code is not clear please let me know and I will respond immediately. Once again I am genuinely sorry for anything miscommunicated and I do appreciate your efforts to help.


    Added after 32 minutes:


    For clarity this is the constructor that I used

    Qt Code:
    1. QTextEdit *qteTestPrintRequest = new QTextEdit("",w);
    To copy to clipboard, switch view to plain text mode 

    Here is the test example text

    Qt Code:
    1. QString qsConcat = "Test Printout For Checking XP Print Request Bug\n";
    2. for (int i=0; i<30; i++){ qsConcat+= "Test Printout for Checking XP Print Request Bug\n" ; }
    3. qteTestPrintRequest->append( qsConcat );
    To copy to clipboard, switch view to plain text mode 

    Here is the key focal point of the thread which involves printing a widget (There was certainly no intent to mention printing a document. I am unsure as to how I gave that impression and I apologise for the confusion)

    Qt Code:
    1. qteTestPrintRequest ->render(&painter);
    To copy to clipboard, switch view to plain text mode 

    I am deliberately trying to render the widget in this way and I am aware that there may be an issue with this line and I have pointed this out in several places above. This approach, which indeed involves rendering a bitmap, worked using several PC/Printer configurations. So far in testing this approach has only caused a problem with 1 particular printer where the application produces a printer document (terminology referring to printer queue) over 4000 times larger. In the other tests for example my test printer configuration produced an equivalent document comprised of 3 full pages rendered using this widget rendering approach with a size of 158KB.

    If this approach is definitely a dead end for any of the reasons I have stated previously or for any other reason then I do need to consider other options although this would obviously incur an unwanted time penalty.

    I have already asked the question
    Will I have to use QTextDocument & html or QGraphicsScene to achieve this end result?



    Added after 1 5 minutes:


    Your information has provided me with many interesting avenues to pursue and I will endeavour to pursue any leads that you produce. For example you have raised the resolution issue. Is the resolution being rendered at the printer related to the pageRect dimensions? There certainly seems to be some correlation.

    If so then the follwing is interesting. The three different resolution settings on my test printer and the HighResolution setting on the problem printer produce the following results:

    Test Printer (No Problem)
    ===================

    Using: QPrinter printer(QPrinter::PrinterResolution);
    xscale,yscale,scale = 6.347, 13.628, 6.347
    printer.pageRect().width() = 4760.0
    printer.pageRect().height() = 6814.0
    QTextEdit.width() = 750.0
    QTextEdit.height() = 500.0
    Printer queue document size 297 KB

    Using: QPrinter printer(QPrinter::ScreenResolution);
    xscale,yscale,scale = 1.016, 2.180, 1.016
    printer.pageRect().width() = 762.0
    printer.pageRect().height() = 1090.0
    QTextEdit.width() = 750.0
    QTextEdit.height() = 500.0
    Printer queue document size 263 KB

    Using: QPrinter printer(QPrinter::HighResolution);
    xscale,yscale,scale = 6.347, 13.628, 6.347
    printer.pageRect().width() = 4760.0
    printer.pageRect().height() = 6814.0
    QTextEdit.width() = 750.0
    QTextEdit.height() = 500.0
    Printer queue document size 297 KB


    Problem Printer (Xerox Work Centre 7428 PS
    =================================

    Using: QPrinter printer(QPrinter::HighResolution);
    xscale,yscale,scale = 6.544, 12.816, 6.544
    printer.pageRect().width() = 4908.0
    printer.pageRect().height() = 6408.0
    QTextEdit.width() = 750.0
    QTextEdit.height() = 500.0
    Printer queue document size 213 MB

    The problem printer queue document size is produced at a very similar scale factor to that of the more reasonable sized HighResolution equivalent on the test printer and yet is over 717 times larger. The ratio of the squares of the scale factors is approximately 1.06:1
    Last edited by Mannion; 12th March 2012 at 15:23.

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter & QPainter render() problem

    Quote Originally Posted by Mannion View Post
    There is no subterfuge here. I am doing exactly what is in the code at the very beginning of the thread. Nothing has changed. I'm not sure where the questions regarding what I am printing are coming from.
    They are coming from my opinion that you are doing something you are not supposed to be doing and I'm wondering if it is on purpose or if you just didn't find a better way of obtaining your goals.

    If this approach is definitely a dead end for any of the reasons I have stated previously or for any other reason then I do need to consider other options although this would obviously incur an unwanted time penalty.
    It's a matter of using the right resolution for printing. If you want to print a widget then its resolution is equal to the resolution of your screen and upscaling it to the maximum resolution supported by a printer doesn't make sense. If you keep the printout resolution in the range of your screen resolution, you should obtain reasonable print jobs.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #19
    Join Date
    Sep 2010
    Posts
    25
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QPrinter & QPainter render() problem

    It's a matter of using the right resolution for printing. If you want to print a widget then its resolution is equal to the resolution of your screen and upscaling it to the maximum resolution supported by a printer doesn't make sense. If you keep the printout resolution in the range of your screen resolution, you should obtain reasonable print jobs.
    This is absolutely not true
    I have just run of a quick confirmation test using the ScreenResolution setting (from a high resolution adapter) The results were dreadful as I have already clearly stated. I am not sure why you find this impossible to believe.

    If a widget is used as a means to rendering a high quality output such as multiple detailed graphs for example as one of my actual application requirements. You often want to render that widget at a much higher resolution than that of the screen. You render the widget off screen and indeed the screen resolution is largely irrelevant. It is then advisable to render at the HighResolution setting. This is exactly what the documentation recommends for high quality printouts.

    They are coming from my opinion that you are doing something you are not supposed to be doing and I'm wondering if it is on purpose or if you just didn't find a better way of obtaining your goals.
    There is still no need for questions as all of the answers are in the source code. It is crystal clear what I am doing. I am either doing it wrong or not there is no lack of clarity as to what I am doing. Indeed I am actually asking if what I am doing is correct, that is the whole point of the thread. I'm not sure how our wires have become so crossed? I am sorry if it is the way that I have framed the question.

    There may be a better way of achieving my goals in respect to some aspects of the problem ie in terms of complete flexibility and best practice etc. However the solution I have tried is a much quicker solution and ticks all the right boxes in terms of quality and indeed queued printer document size apart from a curious specific printer issue which you have never directly addressed. This is why it was a very deliberate approach with an awareness, that I clearly stated, that there are other potential approaches.

    If indeed the only response is never render a widget directly then there should not be so much information readily available showing how to do it. Also this response could have been stated after my first post after a cursory look at my source code. From the information supplied this is not however clear. Why the difference between the test printers and the problem printer? That is surely a useful question. Why do the file sizes not match your explanation of it all being down to resolution dimensions. Look at the figures it simply is not.
    Last edited by Mannion; 12th March 2012 at 17:54.

  21. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPrinter & QPainter render() problem

    Quote Originally Posted by Mannion View Post
    This is absolutely not true
    What exactly is not true? The Nyquist-Shannon sampling theorem?

    I have just run of a quick confirmation test using the ScreenResolution setting (from a high resolution adapter) The results were dreadful as I have already clearly stated.
    I have no idea what you consider "dreadful".

    I am not sure why you find this impossible to believe.
    Because the laws of physics are identical to everyone.

    If a widget is used as a means to rendering a high quality output such as multiple detailed graphs for example
    This is just silly. "Widgets" and "high quality" are nowhere near each other. If you want a graph then render a graph, not a widget.

    You render the widget off screen and indeed the screen resolution is largely irrelevant. It is then advisable to render at the HighResolution setting. This is exactly what the documentation recommends for high quality printouts.
    You mean the documentation actually advises you to render widgets? Could you point me to the relevant paragraph?

    Indeed I am actually asking if what I am doing is correct
    Generally speaking yes, but when it comes to your printer then apparently no. Apparently your printer driver takes a bitmap and converts each pixel of it to post-script definition instead of taking the original vector definition and using that for printout. Since you force rasterization of your data by rendering a widget to a bitmap, you surrender the vector definition of your scene in favour of a finite resolution (whatever you choose it to be).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 08:25
  2. QPainter bug or QPrinter bug?
    By lni in forum Qt Programming
    Replies: 6
    Last Post: 30th March 2009, 02:48
  3. How to render the contents of QPrinter to QWidget
    By nifei in forum Qt Programming
    Replies: 0
    Last Post: 6th March 2009, 05:25
  4. QPainter & QPrinter on linux (fedora 7)
    By wbt_ph in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2007, 16:37
  5. QPainter & QPrinter
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2006, 15:19

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.