Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw a QFont anti-aliased when the OS has anti-alias turned off?

When I use a QPainter to drawText onto a QPixmap using a QFont, it appears anti-aliased when the OS has anti-alias enabled, but not when it doesn't even though I am explicitly setting render hints of the painter and strategy of the font:

QPainter painter(&pixmap);
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
font.setStyleStrategy(QFont::NoSubpixelAntialias); // I do not want clear-type

I know the OS (Windows 7 in this case) is capable of drawing anti-aliased text when anti-alias text is turned off at the OS level because visual studio does this.

How do I get Qt to override this OS's anti-alias setting?

Search term: antialias

like image 826
jtooker Avatar asked Oct 29 '25 16:10

jtooker


1 Answers

You need to make sure you add QFont::PreferAntialias to your font.setStyleStrategy call. Like so:

font.setStyleStrategy(QFont::NoSubpixelAntialias | QFont::PreferAntialias);
like image 68
Will Bickford Avatar answered Nov 01 '25 06:11

Will Bickford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!