首页 > 解决方案 > PyQt5 中的字体无法正确显示

问题描述

我正在尝试在 Python 3.8 下使用 PyQt5 构建一个基本的 gui-Window。这是我正在使用的代码:

from PyQt5 import QtWidgets
from PyQt5 import QtGui
import sys


class Window(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle('Label')
        self.setGeometry(1000,1000,1000,1000)

        self.label_1 = QtWidgets.QLabel(self)
        self.label_1.setText('Welcome to the App')

        self.show()

# create pyqt5 App
App = QtWidgets.QApplication(sys.argv)

# create instance of Window
window = Window()

sys.exit(App.exec())

当我尝试运行它时收到以下错误消息(操作系统:Windows 10):

qt.qpa.fonts: Unable to enumerate family ' "Droid Sans Mono Dotted for Powerline" ' 
qt.qpa.fonts: Unable to enumerate family ' "Droid Sans Mono Slashed for Powerline" ' 
qt.qpa.fonts: Unable to enumerate family ' "Roboto Mono Medium for Powerline" ' 
qt.qpa.fonts: Unable to enumerate family ' "Ubuntu Mono derivative Powerline" '

标签也没有完全显示在我正在创建的窗口中。我已经尝试使用 Application.setFont("Arial") 方法将整个应用程序的字体设置为“Arial”,并通过以下方式直接设置标签的字体:

self.label_1.setFont(QtGui.QFont('Arial'))

这两个都没有改变我窗口中标签的外观。

标签: pythonpyqtpyqt5

解决方案


推荐阅读