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

Don't import QtGui when loading QtCore unless required #496

Open
StSav012 opened this issue Oct 17, 2024 · 0 comments
Open

Don't import QtGui when loading QtCore unless required #496

StSav012 opened this issue Oct 17, 2024 · 0 comments

Comments

@StSav012
Copy link
Contributor

StSav012 commented Oct 17, 2024

To make up mightBeRichText, QtGui is being imported in the following lines:

qtpy/qtpy/QtCore.py

Lines 103 to 112 in b851e00

# Missing QtGui utility functions on Qt
if getattr(Qt, "mightBeRichText", None) is None:
try:
from PySide2.QtGui import Qt as guiQt
Qt.mightBeRichText = guiQt.mightBeRichText
del guiQt
except ImportError:
# Fails with PySide2 5.12.0
pass

qtpy/qtpy/QtCore.py

Lines 132 to 137 in b851e00

# Missing QtGui utility functions on Qt
if getattr(Qt, "mightBeRichText", None) is None:
from PySide6.QtGui import Qt as guiQt
Qt.mightBeRichText = guiQt.mightBeRichText
del guiQt

I suppose the function is not something widely used, so the imports slow the module initiating down.

I'd implement the function this way (and similarly for PySide2):

    # Missing QtGui utility functions on Qt
    if not hasattr(Qt, "mightBeRichText"):
        def _mightBeRichText(*args, **kwargs):
            from PySide6.QtGui import Qt as guiQt

            return guiQt.mightBeRichText(*args, **kwargs)

        Qt.mightBeRichText = _mightBeRichText

Furthermore, this seems to bypass PYSIDE-2898.

But then, what about convertFromPlainText, which is also defined in QtGui.Qt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant