Qt QLabel 字体设置:指南与示例代码
要设置QLabel的字体样式,可以使用setFont()方法。下面是一个示例代码:
from PyQt5.QtWidgets import QApplication, QLabel, QWidget
from PyQt5.QtGui import QFont
app = QApplication([])
window = QWidget()
label = QLabel('Hello World')
font = QFont()
font.setPointSize(20) # 设置字体大小
font.setBold(True) # 设置为粗体
font.setItalic(True) # 设置为斜体
label.setFont(font)
window.show()
app.exec()
在上面的代码中,我们创建了一个QLabel对象,并使用setFont()方法设置了字体样式。通过QFont对象,我们可以设置字体的大小、粗体和斜体等属性。最后,我们显示了窗口并启动了应用程序的事件循环。
希望对你有所帮助!
原文地址: https://www.cveoy.top/t/topic/qfjF 著作权归作者所有。请勿转载和采集!