Why fonts in Qt are appearing blurry or pixelated?

笑着哭i 提交于 2020-05-23 18:26:51

问题


All my fonts are appearing pixelated, so I used AntiAliasing but it isn't helping out. As you can see the pixelated font in the image itself:

This is the code I am currently using:

butt1 = QtWidgets.QLabel("""Scrappr""")
font = QtGui.QFont()
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
font.setPixelSize(22)
font.setFamily('Segoe UI Bold')
butt1.setFont(QtGui.QFont(font))

I tried different solutions on SO, qtforums etc but nothing works for me :(

I tried:

  • Different combinations of ClearType text but It didn't work out as, by default all the text appears good on windows and chrome but with Qt only, it becomes pixelated.

  • Changing windows aero theme to classic one...

But none of them helped.

Here are My PC Specs:

  • windows: 7 ultimate
  • PySide2 version: 5.14.2.1
  • Resolution: 1360 X 768

回答1:


I happen to work with Qt last year and i used qml for building the UI part of my application.

Qt itself prefers us to use qml for building UI, since they have written a UI engine that renders everything better compared to the old engines.

In case of PyQt you are using the python only approach which is only not usually recommended, i am not saying that the qml version is pixel perfect. it still works bad at drawing curves (but that is not the stuff we usually require). As far as your problem is concerned qml will work fine for you (it has much better text rendering).

You might struggle a bit finding the learning resource for qml. But at least give it a shot and yes it is easier much easier than Python only approach.




回答2:


Try to see the fonts used by PyQt5:

import PyQt5
from pyQt5 import QtGui
dir(QtGui.QFont)

the result will show all you need for QFond and the fonts can be used:

[..., 'Helvetica',...,'SansSerif',..., 'Serif',..., 'Times', ...

You can try to add your custom fonts but you need to test each font.

For example, the documentation tells us:

In Windows a request for the “Courier” font is automatically changed to “Courier New”, an improved version of Courier that allows for smooth scaling. The older “Courier” bitmap font can be selected by setting the PreferBitmap style strategy (see setStyleStrategy() ). Once a font is found, the remaining attributes are matched in order of priority:

fixedPitch()

pointSize() (see below)

weight()

style()


来源:https://stackoverflow.com/questions/61697971/why-fonts-in-qt-are-appearing-blurry-or-pixelated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!