1 Attachment(s)
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:
Code:
QFont font
= painter
->font
();
font.
setStyleStrategy(QFont::NoAntialias);
painter->setFont(font);
painter->drawText( sRect, str, _pd->m_textOp );
The texts perfomed well in the viewport, but in the print preview and printed pages that texts was still antialiased.
Attachment 11317
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?
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,
_
Re: How to disable the text antialias option when printing QGraphicsScene to a printe
Quote:
Originally Posted by
anda_skoa
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:
Code:
QFont font
= painter
->font
();
font.
setStyleStrategy(QFont::NoAntialias);
painter->setFont(font);
painter
->setRenderHint
(QPainter::Antialiasing,
false);
painter
->setRenderHint
(QPainter::TextAntialiasing,
false);
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. :(
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,
_
Re: How to disable the text antialias option when printing QGraphicsScene to a printe
Quote:
Originally Posted by
anda_skoa
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)
Re: How to disable the text antialias option when printing QGraphicsScene to a printe
Quote:
Originally Posted by
momo
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
But I rendered the scene to image, it had not any problem.
Ok, that is already good.
Quote:
Originally Posted by
momo
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
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,
_
2 Attachment(s)
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:
Code:
void MyWidget
::slotPaintRequested(QPrinter *printer
)
{
painter.
drawImage(QPoint(0,
10), image1
);
font.setPointSize(10);
painter.setFont(font);
painter.
drawText(QPoint(20,
30),
"Hello World");
painter.
drawImage(QPoint(100,
10), image2
);
}
here is the picture:
Attachment 11328Attachment 11327
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?
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,
_
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.
4 Attachment(s)
Re: How to disable the text antialias option when printing QGraphicsScene to a printe
I tried another test, and found some clues.
Attachment 11329
This image is an rect filled with red.
Attachment 11330
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:
Attachment 11331
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:
Attachment 11332
We can see the line and the text in the area of transparent image had become Blurry.
Re: How to disable the text antialias option when printing QGraphicsScene to a printe
Quote:
Originally Posted by
momo
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,
_
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.:crying: