PyQt5:pyuic5-未知的Qt小部件:QKeySequenceEdit

时间:2019-01-03 15:28:18

标签: python pyqt pyqt5 qt-designer

使用Qt Designer 5.11.1构建了一个ui,我添加了一个QKeySequenceEdit。现在尝试将ui转换为.py,并收到以下错误。

PS C:\dev\app> pyuic5 app.ui > appui.py
Unknown Qt widget: QKeySequenceEdit

这只是带有按键序列编辑的简单ui。

app.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>

1 个答案:

答案 0 :(得分:1)

这似乎是一个错误,因此,如果解决方案是修改/usr/lib/python3.7/site-packages/PyQt5/uic/Compiler/qtproxies.py中的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