Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qtpy.uic.loadUi fails with QWebEngineView #411

Open
owillebo opened this issue Mar 10, 2023 · 2 comments
Open

qtpy.uic.loadUi fails with QWebEngineView #411

owillebo opened this issue Mar 10, 2023 · 2 comments
Assignees
Labels
Milestone

Comments

@owillebo
Copy link

Running;
Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Python 3.11.2 (main, Feb 9 2023, 15:00:29) [GCC 10.2.1 20210110] on linux
QtPy==2.3.0
PySide6==6.4.2

I used Qt Designer to create a simple Main Window with a QWebEngineView and saved it as untitled.ui which is zipped and attached;
untitled.zip

Now when untitled.ui is loaded using qtpy.uic.loadUi an exception is raised;

Traceback (most recent call last):
  File "C:\Temp\issue.py", line 10, in <module>
    widget = loadUi(r"untitled.ui")  # This results in a ModuleNotFoundError.
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\python311\Lib\site-packages\qtpy\uic.py", line 237, in loadUi
    customWidgets = _get_custom_widgets(uifile)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\python311\Lib\site-packages\qtpy\uic.py", line 207, in _get_custom_widgets
    module = importlib.import_module(cw_header)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'QtWebEngineWidgets/QWebEngineView'

With PySide6.QtUiTools.QUiLoader, untitled.ui loads as expected.

See attached issue.py; issue.zip

@CAM-Gerlach
Copy link
Member

Thanks for your detailed report!

Seems like the proximate issue is that

module = importlib.import_module(cw_header)
is attempting to manually load the Python modules corresponding to the Qt headers listed under the custom widgets section in the ui file, but naively doing so in a way that won't actually work with a location type spec.

Namely, it attempts to load the relative path to the header as a single Python module, when in fact it is only the first element of the path before the / that is the actual module name. Furthermore, it doesn't not properly specify this as a submodule of the currently selected binding (namely PySide6 in your case), but rather as a top-level standalone module, which also wouldn't work.

However, recommending a desired solution is well beyond my subject matter expertise. @dalthviz ?

@dalthviz dalthviz added this to the v2.4.0 milestone Mar 21, 2023
@dalthviz dalthviz changed the title qtpy.uic.loadUi fails with QWebEngineView qtpy.uic.loadUi fails with QWebEngineView Aug 11, 2023
@dalthviz
Copy link
Member

Quite late but checking seems like we should thoroughly review the UiLoader class and loadUi definitions (I think those definitons come from efforts to support PySide and PySide2 compatibility and seems like they were meant to work following the behavior of PyQt4 🤔). Also, we should not use them for PySide6 and instead do some changes similar to what was done for loadUiType at #440

Will try to fix this 👍

@dalthviz dalthviz self-assigned this Aug 11, 2023
@dalthviz dalthviz changed the title qtpy.uic.loadUi fails with QWebEngineView qtpy.uic.loadUi fails with QWebEngineView Aug 11, 2023
@dalthviz dalthviz modified the milestones: v2.4.0, v2.4.1 Aug 21, 2023
@dalthviz dalthviz modified the milestones: v2.4.1, v2.4.2 Oct 16, 2023
@ccordoba12 ccordoba12 modified the milestones: v2.4.2, v2.4.3 Oct 12, 2024
@dalthviz dalthviz modified the milestones: v2.4.3, v2.4.4 Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants