QPainter :: rotate disables anti-aliasing of drawn text

I use QPainter::setRenderHint(QPainter::Antialiasing, true) to tell Qt that I want it to smooth out any drawing I make (in this case, the text is drawn using drawText() ).

This works fine and the text looks good until I want to rotate the pixmap map that I draw, for example

 Painter.translate(0, height()); Painter.rotate(-90); 

(to rotate the QPainter 90 degrees counterclockwise and bring it back)

The call to rotate() seems to turn off anti-aliasing for any text drawn - the text is drawn with proper rotation, but without anti-aliasing. Other things seem unaffected - for example, drawLine() still draws a beautifully smooth line.

Any idea what I'm doing wrong?

EDIT: Unsurprisingly, adding text to the path, and then filling out this path, I get smoothed, rotating text. I would rather avoid this route if possible, though.

EDIT (again): I tried using QFont::setStyleStrategy(QFont::PreferAntialias) for the font I am using, without effect. However, a few more experiments show that a basic font such as Arial will still produce smoothed text when rotated, while my custom font (Swiss721 BlkCn BT for anyone interested) will not. Moreover, although this problem exists in Windows 7, I do not have the same problem when working on Ubuntu. This frequently asked question article may seem like Qt is accessing the host operating system to handle font smoothing, so what problems can Windows have when processing rendering from this particular font (which is TrueType, like Arial)?

EDIT (last time, I promise): Increasing the font size to 16pt or higher will fix this problem. It would seem that the problem is that my font is below 16pt - maybe something is related to what was mentioned in the above blog article ?:

In Windows 2000, fonts are usually not smoothed over a certain range (say, sizes 8-16) to make text clearer and easier to read.

+6
source share
2 answers

Recently, I have really come to this part of Qt code, and I think that the behavior you see is related to the following two errors in Qt:

If I remember correctly (not 100%), then what you actually see is the loss of ClearType rendering on Windows. When transform is applied, Qt gets the glyph pixels in a way that produces ClearType information, so things look more jagged.

If you want to see the code yourself, the most likely place would be /src/gui/text/qfontengine_win.cpp . You can also try disabling ClearType and see if they are alike.

+2
source

One hunch applies to your RenderHint. Here you are using QPainter::Antialiasing . Docu: "Indicates that the engine should smooth edges of primitives , if possible." Primitives such as lines, rectangles, etc. Instead, try QPainter::TextAntialiasing .

Note. RenderHints are flags, so you can use bit-OR if necessary (and it sounds as it is).

0
source

Source: https://habr.com/ru/post/900696/


All Articles