No QImage.Format_RGB888 (PyQt6)
-
Is code
import sys from PyQt6.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget, QScrollArea from PyQt6.QtGui import QImage, QPixmap import cv2 class MyDialog(QWidget): def __init__(self): super().__init__() image = cv2.imread('/path/to/file.jpg') height, width, channel = image.shape bytes_per_line = 3 * width q_image = QImage(image.data, width, height, bytes_per_line, QImage.Format_RGB888) image_label = QLabel(self) image_label.setPixmap(QPixmap.fromImage(q_image)) scroll_area = QScrollArea(self) scroll_area.setWidget(image_label) scroll_area.setWidgetResizable(True) layout = QVBoxLayout(self) layout.addWidget(scroll_area) if __name__ == '__main__': app = QApplication(sys.argv) dialog = MyDialog() dialog.show() sys.exit(app.exec_())
Is error
AttributeError: type object 'QImage' has no attribute 'Format_RGB888'
Analogous code for C++ has QImage::Format_RGB888
-
Is code
import sys from PyQt6.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget, QScrollArea from PyQt6.QtGui import QImage, QPixmap import cv2 class MyDialog(QWidget): def __init__(self): super().__init__() image = cv2.imread('/path/to/file.jpg') height, width, channel = image.shape bytes_per_line = 3 * width q_image = QImage(image.data, width, height, bytes_per_line, QImage.Format_RGB888) image_label = QLabel(self) image_label.setPixmap(QPixmap.fromImage(q_image)) scroll_area = QScrollArea(self) scroll_area.setWidget(image_label) scroll_area.setWidgetResizable(True) layout = QVBoxLayout(self) layout.addWidget(scroll_area) if __name__ == '__main__': app = QApplication(sys.argv) dialog = MyDialog() dialog.show() sys.exit(app.exec_())
Is error
AttributeError: type object 'QImage' has no attribute 'Format_RGB888'
Analogous code for C++ has QImage::Format_RGB888
-