Results 1 to 12 of 12

Thread: How to disable the text antialias option when printing QGraphicsScene to a printer?

  1. #1
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question How to disable the text antialias option when printing QGraphicsScene to a printer?

    Hello everyone,

    I want to print some texts without antialias option to a printer, so I added some code like this:
    Qt Code:
    1. QFont font = painter->font();
    2. font.setStyleStrategy(QFont::NoAntialias);
    3. painter->setFont(font);
    4. painter->drawText( sRect, str, _pd->m_textOp );
    To copy to clipboard, switch view to plain text mode 
    The texts perfomed well in the viewport, but in the print preview and printed pages that texts was still antialiased.
    untitiled.jpg
    Left part of the picture shows that how a text displayed in viewport, and right part shows that text displayed in the print preview window.
    The small antialiased text performed terrible in the black and white printer so I have to disable that option, is there anyone who can help me?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    Hmm, I guess you already checked, but jsut in case: is antialising "on" on the painter?

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    Quote Originally Posted by anda_skoa View Post
    Hmm, I guess you already checked, but jsut in case: is antialising "on" on the painter?

    Cheers,
    _
    Thank you for your reply.
    I've tried to use RenderHint to turn off the option, like this:
    Qt Code:
    1. QFont font = painter->font();
    2. font.setStyleStrategy(QFont::NoAntialias);
    3. painter->setFont(font);
    4. painter->setRenderHint(QPainter::Antialiasing, false);
    5. painter->setRenderHint(QPainter::TextAntialiasing, false);
    To copy to clipboard, switch view to plain text mode 

    but it still not working, the text in the viewport is showed correct, but when I open print preview window, the text in the window is antialiasing again.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    Does it only affect the preview or the print itself?
    E.g. try printing into a PDF.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    Quote Originally Posted by anda_skoa View Post
    Does it only affect the preview or the print itself?
    E.g. try printing into a PDF.

    Cheers,
    _
    I've been tring to print to PDF, it is not working. But I rendered the scene to image, it had not any problem.
    So I guess there have some special processes in the QPrintPreviewWidget.
    Or it does the matter of the point size of the text?(I used point size to define the size of text)
    Last edited by momo; 14th August 2015 at 03:39.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    Quote Originally Posted by momo View Post
    I've been tring to print to PDF, it is not working.
    Which approach did you try?
    Setting the output file name on QPrinter or using QPdfWriter?

    Quote Originally Posted by momo View Post
    But I rendered the scene to image, it had not any problem.
    Ok, that is already good.

    Quote Originally Posted by momo View Post
    So I guess there have some special processes in the QPrintPreviewWidget.
    It could depend on the paint device that the QPainter is operating on.

    Quote Originally Posted by momo View Post
    Or it does the matter of the point size of the text?(I used point size to define the size of text)
    Could be, but I think you would then also observe the problem when rendering into an image.

    Cheers,
    _

  7. #7
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    I found several clues there days, maybe it is not the problem of antialias,
    I tried to draw an image and an text and then printed them to a pdf file,
    Here is the part of the test code:
    Qt Code:
    1. void MyWidget::slotPaintRequested(QPrinter *printer)
    2.  
    3. {
    4. QPainter painter( printer );
    5.  
    6. QImage image1("E:/aaa.png");
    7. painter.drawImage(QPoint(0, 10), image1);
    8.  
    9. QFont font;
    10. font.setPointSize(10);
    11. painter.setFont(font);
    12. painter.drawText(QPoint(20, 30), "Hello World");
    13.  
    14. QImage image2("E:/aaa.png");
    15. painter.drawImage(QPoint(100, 10), image2);
    16. }
    To copy to clipboard, switch view to plain text mode 
    here is the picture:
    preview.jpgpdf.jpg
    The first pic is the one showed in preview dialog, the second is the one in the pdf file(both zoom out to 800%).
    We can see the image in pdf file is blured and the text near to the image was affected too.
    In some complex situations(some images in the scene), these images would affected the most area.
    I could not find the solution yet, is there any method to avoid there problem?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    Can you check if there is any difference if you use QPdfWriter?

    Cheers,
    _

  9. #9
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    I used the print function of QPrintPreviewDialog and set the selected printer to "Foxit Reader PDF Printer".
    I found that when I setted the quality of export pdf to a higher level, the problem is relieved but not avoided, and I printed them to a real printer, is had the same problem.

  10. #10
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    I tried another test, and found some clues.
    a.png
    This image is an rect filled with red.
    b.png
    And this one is filled with transparent(not white).
    First time,I painted the first image, a line, and some text, then I printed them, the picture is like this:
    a1.jpg
    Second time, I painted the first image, the second image, a line, and some text(which means there had an invisible image between the frist image and the other shapes), then I printed them, the picture is like this:
    b1.jpg
    We can see the line and the text in the area of transparent image had become Blurry.

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    Quote Originally Posted by momo View Post
    I used the print function of QPrintPreviewDialog and set the selected printer to "Foxit Reader PDF Printer".
    I found that when I setted the quality of export pdf to a higher level, the problem is relieved but not avoided, and I printed them to a real printer, is had the same problem.
    Repeating myself: what if you directly generate PDF using QPdfWriter?

    Cheers,
    _

  12. #12
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to disable the text antialias option when printing QGraphicsScene to a printe

    Our project is developed by Qt 4.8.3 so I could not use QPdfWriter.

Similar Threads

  1. Replies: 0
    Last Post: 29th April 2013, 12:47
  2. Replies: 0
    Last Post: 12th January 2012, 20:06
  3. RichText printing with HighResolution printer
    By ghorwin in forum Qt Programming
    Replies: 1
    Last Post: 31st July 2009, 11:04
  4. font Kerning while printing on printer in 4.4 beta1
    By vladeck in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2008, 01:27
  5. Printing a PRN file on an NDPS printer
    By janca in forum General Discussion
    Replies: 4
    Last Post: 20th March 2006, 23:11

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.