QPainter drawtext blurred text
-
Hi @PabloArg ...
use setRenderHints(QPainter::Antialiasing) with Qpainter. -
Hi Venkatesh, many thanks for your quick reply, but I tried with setRenderHints using the option that you mention as well I used TextAntialiing and I got same results.
I using Qt creator qt-opensource-windows-x86-mingw530-5.8.0.
QImage image(ancho,alto, QImage::Format_ARGB32);
// image.fill(0);
image.fill(Qt::white);
QPainter painter;
painter.setRenderHints(QPainter::Antialiasing);
painter.begin(&image);
painter.save();
// painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.setFont(font);
painter.setPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::RoundCap));
QRectF r1(0, 0, ancho-1,alto-1);
// painter.drawRect(r1);
painter.drawText(r1,Qt::AlignCenter,Texto);
image.save("Texto.png");
painter.restore();
painter.end();painter.end();
-
-
Hi Eeli K, Well when you run the code Sharp edges are because setbold is false.
When setbold is true it looks blurry.I will post my code again, when you get the picture open with GIMP or Other and make zoom up to 300 and will be very clear the problem.
QString Texto = QDateTime::currentDateTime().toString(); QFont font; font.setBold(true); font.setFamily("Helvetica"); font.setStyleStrategy(QFont::PreferAntialias); font.setPixelSize(12); font.setStyleHint(QFont::SansSerif,QFont::PreferOutline); QFontMetrics fm(font); qreal ancho = fm.width(Texto); qreal alto = fm.height(); QImage image(ancho,alto, QImage::Format_ARGB32); // image.fill(0); image.fill(Qt::white); QPainter painter; painter.begin(&image); painter.setRenderHints(QPainter::TextAntialiasing,true); painter.setRenderHints(QPainter::Antialiasing,true); painter.save(); // painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.setFont(font); painter.setPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::RoundCap)); QRectF r1(0, 0, ancho-1,alto-1); // painter.drawRect(r1); painter.drawText(r1,Qt::AlignCenter,Texto); // painter.drawText(10,10,100,100,Qt::AlignCenter,Texto); image.save("Texto.png"); painter.restore(); painter.end();
-
@PabloArg
Hi i use
www.postimage.org
and then just paste link here.
( the Direct Link) -
-
Ahh
Its when inside the PDF ?
Since you print it to image and then print image to pdf, its not
a vector font anymore.
its simply a image of a font/text and will get ugly when zoomed. -
@PabloArg
No, not like that.
It is vector but you make it part of an image and i think
what you mean is that is not scaling nicely as other text in pdf normally do ?
The reason for that is its no longer text, just pixels on image.Try drawing the text directly on the Printer painter
QPrinter printer;
QPainter painter(&printer);
printer.setOutputFileName("c:\temp\file.pdf");
printer.setOutputFormat(QPrinter::PdfFormat);
painter.drawText(xxx)