为什么 Qt 中的字体看起来模糊或像素化? [英] Why fonts in Qt are appearing blurry or pixelated?
问题描述
我所有的字体都出现像素化,所以我使用了 AntiAliasing
但它没有帮助.正如您在图像本身中看到的像素化字体:
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))
我在 SO、qtforums 等上尝试了不同的解决方案,但对我没有任何效果:(
I tried different solutions on SO, qtforums etc but nothing works for me :(
我试过了:
ClearType text
的不同组合,但效果不佳,默认情况下,所有文本在 windows 和 chrome 上都显示良好 但 与仅限 Qt
,它会变得像素化.
Different combinations of
ClearType text
but It didn't work out as, by default all the text appears good on windows and chrome but withQt
only, it becomes pixelated.
将 windows aero 主题更改为经典主题...
Changing windows aero theme to classic one...
但他们都没有帮助.
这是我的电脑规格:
- Windows:7 终极版
- PySide2 版本:5.14.2.1
- 分辨率:1360 X 768
推荐答案
我使用的是 BrownPro 字体,文字在所有分辨率下都很模糊,但在低分辨率下更明显.
I'm using BrownPro font and the texts were blurry at all resolutions, but much more evident at low resolutions.
我能够通过将字体的提示首选项设置为:PreferNoHinting
来解决该问题.在应用程序级别应用它,可以解决所有问题.
I was able to solve the issue by setting the hinting preference for the font to: PreferNoHinting
. Applying it at the application level, fixes the issue everywhere.
这里是文档:https://doc.qt.io/qt-5/qfont.html#HintingPreference-enum
这是我使用的代码:
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Light.ttf");
QFont brown_pro_font("BrownPro");
brown_pro_font.setHintingPreference(QFont::HintingPreference::PreferNoHinting); //This line did the trick
QApplication::setFont(brown_pro_font);
这篇关于为什么 Qt 中的字体看起来模糊或像素化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!