Details

    • Type: Bug
    • Status: Reported
    • Priority: Not Evaluated
    • Resolution: Unresolved
    • Affects Version/s: 5.13.0
    • Fix Version/s: None
    • Component/s: PySide
    • Labels:
      None
    • Environment:
      python 3.6, PySide 5.13, windows 10
    • Platform/s:
      Windows

      Description

      When painting a QPixmap on a QWidget, with different sizes for the pixmap and the widget, it fails for some sizes and works for others. And for some shapes, it makes my program crash.

      I posted an example of code causing the bug and a screenshot with various image shapes here : https://stackoverflow.com/questions/57071137/issue-when-drawing-a-numpy-array-into-a-qwidget

      Here is the code. Note that silx.qt is a wrapper on multiple python qt wrappers (pyqt4, pyside, pyqt5, pyside2) that flattens the namespace. I verified that it was actually PySide 5.13 loaded.

      I also verified that the bug does not occur with PyQt5 with the exact same code.

      from silx.gui import qt
      import numpy
      
      
      GRAY_COLORTABLE = []
      for i in range(256):
          GRAY_COLORTABLE.append(qt.qRgb(i, i, i))
      
      
      class PreviewImageWidget(qt.QWidget):
          """Preview image"""
          def __init__(self, parent=None):
              super().__init__(parent)
              self.pixmap = qt.QPixmap()
              self.setFixedSize(350, 350)
      
          def paintEvent(self, event):
              painter = qt.QPainter(self)
              painter.drawPixmap(self.rect(), self.pixmap)
      
          def setImage(self, img_array):
              # TODO : adjust colortable to actual dtype (autoscale to min - max ??)
              if img_array is None:
                  self.pixmap = qt.QPixmap()
              else:
                  if img_array.dtype != numpy.uint8:
                      max_value = img_array.max()
                      img_array = 256. / max_value * img_array
                      img_array = img_array.astype(numpy.uint8)
      
                  # binary images are of dtype uint8
                  if img_array.max() == 1:
                      img_array = img_array * 255
                  image = qt.QImage(img_array,
                                    img_array.shape[1], img_array.shape[0],
                                    qt.QImage.Format_Indexed8)
                  image.setColorTable(GRAY_COLORTABLE)
                  self.pixmap = qt.QPixmap.fromImage(image)
      
              self.update()
      
      if __name__ == '__main__':
      
          app = qt.QApplication([])
          allPreviewWidgets = []
      
          for sh in [(610, 500), (450, 700), (550, 600),
                     (500, 500), (510, 500), (500, 520)]:
              img_array = numpy.zeros(sh, dtype=numpy.uint8)
              img_array[200:350, 250:300] = 1
      
              previewWidget = PreviewImageWidget()
              previewWidget.setWindowTitle(str(img_array.shape))
              previewWidget.show()
              previewWidget.setImage(img_array)
              allPreviewWidgets.append(previewWidget)
      
          app.exec_()
      

        Attachments

        1. Capture.PNG
          58 kB
          PiRK
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              crmaurei Cristian Maureira-Fredes
              Reporter:
              pirk PiRK
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes