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

Viewed 1044

I'm trying to port a code from PyQt5 to PyQt6, but the following error occur:

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

It happens with any Format_*, although in the PyQt6 QImage documentation these formats are present.

Python 3.9 installed with miniforge, Mac M1 with OS X 11.5.2

Thanks.

1 Answers

Ok, found the solution myself.

Although in PySide6's doc ( https://doc.qt.io/qtforpython/PySide6/QtGui/QImage.html ) these constants are still written in PyQt5's way, they are now stored in the Format enum. The port from PyQt5 to PyQt6 is then:

PyQt5:

QImage.Format_RGB888

PyQt6:

QImage.Format.Format_RGB888

This applies to all Format_* constants of QImage.

Related