[PyQt] PyQt5.uic.loadUiType() ignores <customwidgets> for main widget class

Kyle Altendorf sda at fstab.net
Sun Aug 4 17:38:28 BST 2019


It looks like presently PyQt5.uic.loadUiType() assumes that the .ui 
file's base widget's class is going to be in PyQt5.QtWidgets.  This is 
not the case for mine which often use a custom type specified in the 
<customwidgets> section.

Rather than:
     return (ui_globals[winfo["uiclass"]], getattr(QtWidgets, 
winfo["baseclass"]))

This seems to work:
     ui_base = ui_globals.get(winfo["baseclass"])

     if ui_base is None:
         ui_base = getattr(QtWidgets, winfo["baseclass"])

     return (ui_globals[winfo["uiclass"]], ui_base)

Example code and output are available at:
     https://gist.github.com/altendky/325d0737a923e6f678617364e0f68f83

Output:
     sys.version: 3.7.4 (default, Aug  2 2019, 12:58:45)
     [GCC 6.3.0 20170516]
     sys.platform: linux
     QT_VERSION_STR: 5.13.0
     PYQT_VERSION_STR: 5.13.0
     SIP_VERSION_STR: 4.19.18
     Traceback (most recent call last):
       File "bad3.py", line 50, in <module>
         main()
       File "bad3.py", line 46, in main
         Ui, UiBase = PyQt5.uic.loadUiType(io.StringIO(ui_text))
       File 
"/home/altendky/st.src/venv/lib/python3.7/site-packages/PyQt5/uic/__init__.py", 
line 204, in loadUiType
         return (ui_globals[winfo["uiclass"]], getattr(QtWidgets, 
winfo["baseclass"]))
     AttributeError: module 'PyQt5.QtWidgets' has no attribute 'MyWidget'

I'll attach my files again here but last time they didn't seem to be 
liked.  If anyone has suggestions on what I should do differently when 
attaching I'm happy to hear them.  I'm using RoundCube webmail.

Cheers,
-kyle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bad3.py
Type: text/x-python
Size: 1169 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190804/6251ac42/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: out
Type: text/x-c
Size: 664 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190804/6251ac42/attachment.bin>


More information about the PyQt mailing list