pyqt5如何改变字体大小
时间: 2023-09-02 13:14:25 浏览: 113
PyQt5中可以使用QFont类来改变字体大小。
以下是一个例子:
```python
from PyQt5.QtWidgets import QApplication, QLabel, QWidget
from PyQt5.QtGui import QFont
import sys
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 创建一个标签
label = QLabel('Hello World', self)
# 创建字体对象
font = QFont('Arial', 20)
# 设置字体大小
font.setPointSize(30)
# 将字体应用到标签上
label.setFont(font)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('PyQt5 Font Example')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
```
在这个例子中,我们创建了一个标签,并使用QFont类来创建字体对象。然后,我们使用setPointSize()方法来设置字体大小,并将字体应用于标签上。
注意:在这个例子中,我们使用了QApplication和QWidget类,这是PyQt5中用于创建GUI应用程序的基本类。在你的代码中可能需要根据实际情况进行调整。
阅读全文
相关推荐















