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

标签 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

<?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/

相关文章:

python - 如何更改 QTextEdit 小部件的颜色

python - 如何从元组填充 QTreeWidget?

python - 为什么这两个平方根算法的运行方式如此不同,尽管它们应该完全相同?

python - 如何打印两个数字的公因数列表?

Python,mysqldb错误1064

python - 使用 PIL 和 PyQt 在小部件上绘制 QImage 时出现错误

python - HTMLParser 的缓冲问题

python - 如何阻止 QSvgWidget 生成它自己的窗口

python - QTableWidget像excel一样显示某些小数

python - 对象中的 AttributeError 没有属性 'toHtml' - pyqt5