mottosso / Qt5.py

Minimal Python 2 & 3 shim around PySide2 and PyQt5
MIT License
33 stars 5 forks source link

Qt5 import issue compared with Qt, PyQt or Pyside #8

Open hannesdelbeke opened 2 years ago

hannesdelbeke commented 2 years ago

the old Qt module can easily subsitute Pyside2 but when trying that with the new Qt5 it has to be done in a specific way.

it doesn't allow us to do this

from PySide2.QtWidgets import QApplication
from Qt.QtWidgets import QApplication
from Qt5.QtWidgets import QApplication  # errors
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
ModuleNotFoundError: No module named 'Qt5.QtWidgets'; 'Qt5' is not a package

This is fine

import PySide2
import Qt
import Qt5

This is fine

from PySide2 import QtWidgets
from Qt import QtWidgets
from Qt5 import QtWidgets
hannesdelbeke commented 2 years ago

which means it's more work to change existing scripts to use Qt5.

example

instead of simply copy pasting Qt5 over PySide2, like this

from Qt5.QtWidgets import QApplication, QWidget
from Qt5.QtGui import QCloseEvent, QIcon, QImage, QPixmap, QWindow
from Qt5.QtCore import QEvent, QObject, QRect, QSettings

I need to do this:

import Qt5
QApplication = Qt5.QtWidgets.QApplication
QWidget = Qt5.QtWidgets.QWidget
QCloseEvent = Qt5.QtGui.QCloseEvent
QIcon = Qt5.QtGui.QIcon
QImage = Qt5.QtGui.QImage
QPixmap = Qt5.QtGui.QPixmap
QWindow = Qt5.QtGui.QWindow
QEvent = Qt5.QtCore.QEvent
QObject = Qt5.QtCore.QObject
QRect = Qt5.QtCore.QRect
QSettings = Qt5.QtCore.QSettings
mottosso commented 2 years ago

Thanks, a PR is very welcome.