1 import sys
2 from PyQt5.QtWidgets import QApplication, QWidget,QLabel
3 from PyQt5.QtGui import QFont
4 from PyQt5 import QtCore
5
6 class MainWindow(QWidget):
7 def __init__(self):
8 super(Demo, self).__init__()
9 self.label = QLabel('hello world',self)
10 #self.label.setFont(QFont("华文琥珀",20,QFont.Bold)) #设置字体、样式和大小
11 #QFont.Bold 加粗
12
13 #self.label.setStyleSheet("color:white") #文本颜色(前景色)
14
15 #self.label.setStyleSheet("background-color: #000000;color: #ffffff") #设置背景色和前景色
16 #self.label.setGeometry(QtCore.QRect(20, 60, 291, 61)) #设置控件的位置和大小
17
18
19
20 #分开设置
21 font = QFont() #实例化字体对象
22 font.setFamily('微软雅黑') #字体
23 font.setBold(True) #加粗
24 font.setItalic(True) #斜体
25 font.setStrikeOut(True) #删除线
26 font.setUnderline(True) #下划线
27 font.setPointSize(23) #字体大小
28 self.label.setFont(font)
29
30
31 #主程序
33 if __name__ == '__main__':
34 app = QApplication(sys.argv)
35 mainwindow = MainWindow()
36 mainwindow.show()
37 sys.exit(app.exec_())
【PyQt5】Qt Designer设计GUI界面之QFont设置字体
最新推荐文章于 2025-03-05 22:38:23 发布