python-3.x - PyQt6: AttributeError: 类型对象 'QImage' 没有属性 'Format_RGB888'

标签 python-3.x pyqt pyqt5 pyqt6

<分区>

我正在尝试将代码从 PyQt5 移植到 PyQt6,但出现以下错误:

AttributeError: type object 'QImage' has no attribute 'Format_RGB888'

它发生在任何 Format_* 中,尽管在 PyQt6 QImage 文档中存在这些格式。

Python 3.9 安装了 miniforge,Mac M1 安装了 OS X 11.5.2

谢谢。

最佳答案

好的,我自己找到了解决方案。

虽然在 PySide6 的文档(https://doc.qt.io/qtforpython/PySide6/QtGui/QImage.html)中,这些常量仍然以 PyQt5 的方式编写,但它们现在存储在 Format 枚举中。那么从 PyQt5 到 PyQt6 的端口是:

PyQt5:

QImage.Format_RGB888

PyQt6:

QImage.Format.Format_RGB888

这适用于 QImage 的所有 Format_* 常量。

关于python-3.x - PyQt6: AttributeError: 类型对象 'QImage' 没有属性 'Format_RGB888',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69572133/

相关文章:

python - PyQt:如何从用户那里获取大量文件名?

python-3.x - 使用 OpenCV QRCodeDetector 读取条形码

Python换行符打印两次

qt - PyQt5翻译: is it possible to run pylupdate5 from Python?

python - 如何更新 GUI pyqt 内热图的颜色条?

python - 在 PyQt5 中停止工作线程中的无限循环最简单的方法

python - 在 Python 中可视化球谐函数

python - str.startswith 是如何真正起作用的?

python - PyQt5 - 无法加载平台插件 "windows"。可用平台最小为 : windows,

python - 我想使用 PyQt5 制作计算器机器人,但出现错误