使用 Qt Designer 5.9.5 构建了一个带有 QFontComboBox 的简单 ui。当我运行 pyuic5 时,它会产生错误;
pyuic5 demoFontComboBox.ui -o demoFontComboBox.py
Unknown C++ class: QfontDatabase
.ui 文件是;
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>240</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<y>50</y>
<width>81</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Select font</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>30</x>
<y>90</y>
<width>81</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Type text</string>
</property>
</widget>
<widget class="QFontComboBox" name="fontSelect">
<property name="geometry">
<rect>
<x>120</x>
<y>40</y>
<width>291</width>
<height>25</height>
</rect>
</property>
<property name="writingSystem">
<enum>QFontDatabase::Any</enum>
</property>
</widget>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<x>120</x>
<y>80</y>
<width>291</width>
<height>101</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
生成部分 .py 文件,如下所示;
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'demoFontComboBox.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(500, 240)
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(30, 50, 81, 17))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(30, 90, 81, 17))
self.label_2.setObjectName("label_2")
self.fontSelect = QtWidgets.QFontComboBox(Dialog)
self.fontSelect.setGeometry(QtCore.QRect(120, 40, 291, 25))
生成的代码似乎缺少 retranslatedUi() 函数声明和调用。
在尝试上述 ui 示例之前和之后,pyuic5 已使用 QLineEdit、QButton、QRadioButton 成功地从 ui 生成文件。