Unknown Qt widget error when importing a .ui file in Python3 using PyQt5?

Question:

When importing an .ui file from QtDesigner into a Python3 file, I am encountering the error message PyQt5.uic.exceptions.NoSuchWidgetError: Unknown Qt widget: KPIM.AddresseeLineEdit. Although my code has worked in previous projects, it is not functioning properly in my current project.

What is KPIM.AddresseeLineEdit and is it a PyQt5 widget?


import sqlite3
from PyQt5.uic import *
from PyQt5.QtWidgets import *

from os import path
import sys

FORM_CLASS,_ = loadUiType(path.join(path.dirname(__file__), "login.ui"))
class Main(QMainWindow, FORM_CLASS):
    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
        self.setupUi(self)

def main():
    app = QApplication(sys.argv)
    window = Main()
    window.show()
    app.exec_()

if __name__ == '__main__':
        main()

Output:

Traceback (most recent call last):
  File "/usr/lib/python3.9/idlelib/run.py", line 559, in runcode
    exec(code, self.locals)
  File "/home/lixt/Desktop/Zamaio/ui/remade/register/zamaio.py", line 8, in <module>
    FORM_CLASS,_ = loadUiType(path.join(path.dirname(__file__), "login.ui"))
  File "/usr/local/lib/python3.9/dist-packages/PyQt5/uic/__init__.py", line 200, in loadUiType
    winfo = compiler.UICompiler().compileUi(uifile, code_string, from_imports,
  File "/usr/local/lib/python3.9/dist-packages/PyQt5/uic/Compiler/compiler.py", line 111, in compileUi
    w = self.parse(input_stream, resource_suffix)
  File "/usr/local/lib/python3.9/dist-packages/PyQt5/uic/uiparser.py", line 1037, in parse
    actor(elem)
  File "/usr/local/lib/python3.9/dist-packages/PyQt5/uic/uiparser.py", line 828, in createUserInterface
    self.traverseWidgetTree(elem)
  File "/usr/local/lib/python3.9/dist-packages/PyQt5/uic/uiparser.py", line 806, in traverseWidgetTree
    handler(self, child)
  File "/usr/local/lib/python3.9/dist-packages/PyQt5/uic/uiparser.py", line 264, in createWidget
    self.stack.push(self.setupObject(widget_class, parent, elem))
  File "/usr/local/lib/python3.9/dist-packages/PyQt5/uic/uiparser.py", line 228, in setupObject
    obj = self.factory.createQObject(clsname, name, args, is_attribute)
  File "/usr/local/lib/python3.9/dist-packages/PyQt5/uic/objcreator.py", line 116, in createQObject
    raise NoSuchWidgetError(classname)
PyQt5.uic.exceptions.NoSuchWidgetError: Unknown Qt widget: KPIM.AddresseeLineEdit

My ui file

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>524</width>
    <height>555</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <property name="styleSheet">
   <string notr="true">background-color: rgb(29, 68, 9);</string>
  </property>
  <widget class="QLabel" name="title">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>10</y>
     <width>521</width>
     <height>41</height>
    </rect>
   </property>
   <property name="statusTip">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="whatsThis">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="styleSheet">
    <string notr="true">color: rgb(25, 255, 0);</string>
   </property>
   <property name="text">
    <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:26pt; font-weight:600;&quot;&gt;Zamaio&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
  <widget class="QLabel" name="username_text">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>120</y>
     <width>121</width>
     <height>31</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>Sans Serif</family>
     <weight>50</weight>
     <italic>false</italic>
     <bold>false</bold>
    </font>
   </property>
   <property name="statusTip">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="whatsThis">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="styleSheet">
    <string notr="true">color: rgb(181, 195, 130);</string>
   </property>
   <property name="text">
    <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:11pt; font-weight:600;&quot;&gt;Username:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
  <widget class="KPIM::AddresseeLineEdit" name="username">
   <property name="geometry">
    <rect>
     <x>130</x>
     <y>120</y>
     <width>221</width>
     <height>28</height>
    </rect>
   </property>
   <property name="styleSheet">
    <string notr="true">background-color: rgb(44, 97, 4);
color: rgb(240, 255, 233);



border-width: 1px;
border-style: solid;
border-color: black black black black;</string>
   </property>
   <property name="maxLength">
    <number>29</number>
   </property>
  </widget>
  <widget class="QLabel" name="password_text">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>170</y>
     <width>121</width>
     <height>31</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>Sans Serif</family>
     <weight>50</weight>
     <italic>false</italic>
     <bold>false</bold>
    </font>
   </property>
   <property name="statusTip">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="whatsThis">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="styleSheet">
    <string notr="true">color: rgb(181, 195, 130);</string>
   </property>
   <property name="text">
    <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:11pt; font-weight:600;&quot;&gt;Password:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
  <widget class="KPIM::AddresseeLineEdit" name="password">
   <property name="geometry">
    <rect>
     <x>130</x>
     <y>170</y>
     <width>221</width>
     <height>28</height>
    </rect>
   </property>
   <property name="styleSheet">
    <string notr="true">background-color: rgb(44, 97, 4);
color: rgb(240, 255, 233);



border-width: 1px;
border-style: solid;
border-color: black black black black;


password::hover {
    border-color: black black white white;

}</string>
   </property>
   <property name="maxLength">
    <number>32</number>
   </property>
   <property name="readOnly">
    <bool>false</bool>
   </property>
   <property name="urlDropsEnabled">
    <bool>false</bool>
   </property>
   <property name="trapEnterKeyEvent" stdset="0">
    <bool>false</bool>
   </property>
   <property name="squeezedTextEnabled">
    <bool>false</bool>
   </property>
   <property name="passwordMode">
    <bool>true</bool>
   </property>
  </widget>
  <widget class="QLabel" name="Age_text">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>370</y>
     <width>121</width>
     <height>41</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>Sans Serif</family>
     <weight>50</weight>
     <italic>false</italic>
     <bold>false</bold>
    </font>
   </property>
   <property name="statusTip">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="whatsThis">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="styleSheet">
    <string notr="true">color: rgb(181, 195, 130);</string>
   </property>
   <property name="text">
    <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:11pt; font-weight:600;&quot;&gt;Age:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
  <widget class="QLabel" name="confirm_password_texr">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>220</y>
     <width>161</width>
     <height>31</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>Sans Serif</family>
     <weight>50</weight>
     <italic>false</italic>
     <bold>false</bold>
    </font>
   </property>
   <property name="statusTip">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="whatsThis">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="styleSheet">
    <string notr="true">color: rgb(181, 195, 130);</string>
   </property>
   <property name="text">
    <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:11pt; font-weight:600;&quot;&gt;Confirm Password:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
  <widget class="KPIM::AddresseeLineEdit" name="confirm_password">
   <property name="geometry">
    <rect>
     <x>180</x>
     <y>220</y>
     <width>171</width>
     <height>28</height>
    </rect>
   </property>
   <property name="styleSheet">
    <string notr="true">background-color: rgb(44, 97, 4);
color: rgb(240, 255, 233);



border-width: 1px;
border-style: solid;
border-color: black black black black;


password::hover {
    border-color: black black white white;

}</string>
   </property>
   <property name="maxLength">
    <number>32</number>
   </property>
   <property name="readOnly">
    <bool>false</bool>
   </property>
   <property name="urlDropsEnabled">
    <bool>false</bool>
   </property>
   <property name="trapEnterKeyEvent" stdset="0">
    <bool>false</bool>
   </property>
   <property name="squeezedTextEnabled">
    <bool>false</bool>
   </property>
   <property name="passwordMode">
    <bool>true</bool>
   </property>
  </widget>
  <widget class="QSlider" name="age_slider">
   <property name="geometry">
    <rect>
     <x>110</x>
     <y>380</y>
     <width>261</width>
     <height>17</height>
    </rect>
   </property>
   <property name="orientation">
    <enum>Qt::Horizontal</enum>
   </property>
  </widget>
  <widget class="QLabel" name="Age_counter">
   <property name="geometry">
    <rect>
     <x>370</x>
     <y>370</y>
     <width>151</width>
     <height>41</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>Sans Serif</family>
     <weight>50</weight>
     <italic>false</italic>
     <bold>false</bold>
    </font>
   </property>
   <property name="statusTip">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="whatsThis">
    <string>Zamaio is a new social platform!</string>
   </property>
   <property name="styleSheet">
    <string notr="true">color: rgb(181, 195, 130);</string>
   </property>
   <property name="text">
    <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;/&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
  <widget class="QPushButton" name="pushButton">
   <property name="geometry">
    <rect>
     <x>380</x>
     <y>470</y>
     <width>90</width>
     <height>28</height>
    </rect>
   </property>
   <property name="styleSheet">
    <string notr="true">QPushButton {
    color: #FFFFFF;
    background-color: rgb(17, 176, 27);
    border-style: outset;
    padding: 2px;
    font: bold 20px;
    border-width: 2px;
    border-radius: 4px;
    border-color: rgb(19, 197, 0);
}


QPushButton:hover {
    background-color: rgb(47, 105, 37);
    border-color: rgb(33, 163, 30);
}


QPushButton::clicked
{
    background-color : red;
}</string>
   </property>
   <property name="text">
    <string>Create</string>
   </property>
  </widget>
  <widget class="QPushButton" name="ViewPass1">
   <property name="geometry">
    <rect>
     <x>360</x>
     <y>170</y>
     <width>31</width>
     <height>28</height>
    </rect>
   </property>
   <property name="text">
    <string/>
   </property>
  </widget>
  <widget class="QPushButton" name="ViewPass1_2">
   <property name="geometry">
    <rect>
     <x>360</x>
     <y>220</y>
     <width>31</width>
     <height>28</height>
    </rect>
   </property>
   <property name="text">
    <string/>
   </property>
  </widget>
 </widget>
 <customwidgets>
  <customwidget>
   <class>KPIM::AddresseeLineEdit</class>
   <extends>QLineEdit</extends>
   <header>LibkdepimAkonadi/AddresseeLineEdit</header>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>

Is there any kind of bug?

Solution

By replace KPIM::AddresseeLineEdit by QTextEdit in the .ui file solves the problem

Asked By: Lixt

||

Answers:

It appears that the issue was caused by using unsupported widgets in PyQt5. I was able to fix it by replacing KPIM::AddresseeLineEdit with QTextEdit in the .ui file. Thank you to @ekhumoro for pointing me in the right direction.

Answered By: Lixt
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.