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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

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

Kyle Altendorf
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,

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:

     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 "", line 50, in <module>
       File "", line 46, in main
         Ui, UiBase = PyQt5.uic.loadUiType(io.StringIO(ui_text))
line 204, in loadUiType
         return (ui_globals[winfo["uiclass"]], getattr(QtWidgets,
     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.


PyQt mailing list    [hidden email] (1K) Download Attachment
out (910 bytes) Download Attachment