python pyqt5 QFontDialog 字体选择框

2019-07-05 11:21:29 浏览数 (1)

-- coding: utf-8 --

''' 【简介】 PyQt5中 QFontDialog 例子

'''

import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import *

class FontDialogDemo(QWidget): def init(self, parent=None): super(FontDialogDemo, self).init(parent) layout = QVBoxLayout() self.fontButton = QPushButton("choose font") self.fontButton .clicked.connect(self.getFont) layout.addWidget(self.fontButton ) self.fontLineEdit = QLabel("Hello,测试字体例子") layout.addWidget(self.fontLineEdit ) self.setLayout(layout) self.setWindowTitle("Font Dialog 例子")

代码语言:javascript复制
def getFont(self):
    font, ok = QFontDialog.getFont()
    if ok:
        self.fontLineEdit .setFont(font)

if name == 'main': app = QApplication(sys.argv) demo = FontDialogDemo() demo.show() sys.exit(app.exec_())

0 人点赞