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

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

bad3.py (1K) Download Attachment
out (910 bytes) Download Attachment