用Qt Designer 5.11.1构建了一个ui,并添加了一个QKeySequenceEdit。现在尝试将 ui 转换为 .py,并收到以下错误。
PS C:\dev\app> pyuic5 app.ui > appui.py
Unknown Qt widget: QKeySequenceEdit
这只是一个带有按键序列编辑的简单用户界面。
应用程序.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QKeySequenceEdit" name="keySequenceEdit">
<property name="geometry">
<rect>
<x>150</x>
<y>380</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
最佳答案
这似乎是一个错误,所以如果解决方案是修改 qtproxies.py (在我的情况下位于 /usr/lib/python3.7/site-packages/PyQt5/uic/Compiler/中) qtproxies.py
并添加一行:
class QtWidgets(ProxyNamespace):
# ...
class QCommandLinkButton(QPushButton): pass
class QKeySequenceEdit(QWidget): pass # add this line
# Add all remaining classes.
for _class in _qwidgets:
if _class not in locals():
locals()[_class] = type(_class, (QWidget, ), {})
还建议您使用-o
而不是>
,因为有时它会导致第二个问题
pyuic5 app.ui -o appui.py -x
关于python - PyQt5:pyuic5 - 未知的 Qt 小部件:QKeySequenceEdit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54025247/