Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. No QImage.Format_RGB888 (PyQt6)
Forum Updated to NodeBB v4.3 + New Features

No QImage.Format_RGB888 (PyQt6)

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 2 Posters 753 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by AndrzejB
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • A AndrzejB

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @AndrzejB
      Python Qt enums have moved at Qt6. Try QImage.Format.Format_RGB888. I don't think you will find documentation yet updated.

      1 Reply Last reply
      1
      • A AndrzejB has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved