python pyqt5 QFontDialog 字体选择框

-- 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 例子")

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_())

你可能感兴趣的:(python pyqt5 QFontDialog 字体选择框)