离线
克隆代码之后, 源码要修改几处, 参考: https://whycan.cn/t_3724.html#p34108
离线
离线
E:\Python37\python.exe nodz_demo.py 运行成功.
离线
终于搞明白了, 上面为什么要用 from Qt,
而不是 from PySide2, 或者 from PyQt5, 又或者 from PyQt4,
因为有了这个: https://github.com/mottosso/Qt.py
只要设置 环境变量 QT_PREFERRED_BINDING 即可,
可以通过以下这种命令行设置:
$ set QT_PREFERRED_BINDING=PyQt5 # Windows
$ export QT_PREFERRED_BINDING=PyQt5 # Unix/OSX
或者用代码设置:
import os
os.environ["QT_PREFERRED_BINDING"] = "PySide";
from Qt import QtCore, QtWidgets
参考: https://fredrikaverpil.github.io/2016/07/25/developing-with-qt-py/
离线
安装Qt.Py:
D:\>d:\Python\Python37\python.exe -m pip install Qt.py
Collecting Qt.py
Downloading https://files.pythonhosted.org/packages/e0/72/d777cb02ead5c6ac0b05
af5911bb02abfbf49b6bd20878684442c8a4c051/Qt.py-1.2.4-py2.py3-none-any.whl
Installing collected packages: Qt.py
Successfully installed Qt.py-1.2.4
现场测试OK:
D:\>set QT_PREFERRED_BINDING=PyQt5
D:\>python -c "import Qt;print(Qt.__binding__)"
PyQt5
D:\>set QT_PREFERRED_BINDING=PyQt4
D:\>python -c "import Qt;print(Qt.__binding__)"
PyQt4
D:\>set QT_PREFERRED_BINDING=PySide2
D:\>python -c "import Qt;print(Qt.__binding__)"
PySide2
D:\>set QT_PREFERRED_BINDING=PySide
D:\>python -c "import Qt;print(Qt.__binding__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\Python\Python37\lib\site-packages\Qt.py", line 1874, in <module>
_install()
File "D:\Python\Python37\lib\site-packages\Qt.py", line 1822, in _install
raise ImportError("No Qt binding were found.")
ImportError: No Qt binding were found.
D:\>
离线
搞定, 只要修改 nodz_demo.py 就可以了:
import os
os.environ["QT_PREFERRED_BINDING"] = "PySide2"
from Qt import QtCore, QtWidgets
import Qt
if Qt.IsPySide2:
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.dirname(Qt.__file__) + "\\" \
+ os.environ["QT_PREFERRED_BINDING"] + "\\plugins\\"
elif Qt.IsPyQt5:
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.dirname(Qt.__file__) + "\\" \
+ os.environ["QT_PREFERRED_BINDING"] + "\\Qt\\plugins\\"
import nodz_main
离线
在 PyCharm 这里填入环境变量也是可以的:
QT_QPA_PLATFORM_PLUGIN_PATH=D:\Python\Python37\Lib\site-packages\PySide2\plugins\platforms
离线
离线
这个有点意思 和 Qt的 NodeEditor 一样的效果,不过python开发更快
离线