admin 發表於 2023-4-1 00:12:18

PyQt Backwards compatibility

If you're developing software that's targeting both PyQt5 and PyQt6 you can use conditional imports to import the classes from whichever module is loaded.
try:
    from PyQt6 import QtWidgets, QtGui, QtCore # ...
except ImportError:
    from PyQt5 import QtWidgets, QtGui, QtCore # ...
If you add these imports to a file in the root of your project named qt.py. You can then, in your own code files import use from qt import QtWidgets and the available library will be imported automatically.
If you use the fully-qualified names for enums and exec() then many applications previously written in PyQt5 will work as-is. However, importing in this way won't work around any of the differences between Qt5 and Qt6 mentioned above. For that, we recommend using the QtPy library.


頁: [1]
查看完整版本: PyQt Backwards compatibility