ImageItem changes its Rectangle after setImage

31 views
Skip to first unread message

Edward Barnard

unread,
Jan 17, 2017, 2:16:57 PM1/17/17
to pyqtgraph
I've encountered an interesting effect of using ImageItem setImage and setRect:

In a loop I want to continually update an the image in ImageItem with new image data. Psuedocode follows:

img_rect = QtCore.QRectF(x0, y0, w, h)
img_item.setRect(img_rect)
for x in range(100):
    img_item.setImage(img_data[x,:,:])

If the image_data has non-square pixels, each setImage will create a bounding box that starts at x0, y0, but will not have the correct width, ie it will be 2x wider if pixel aspect ratio is 2:1. 

The fix that I had was to repeatedly setRect after each setImage:

img_rect = QtCore.QRectF(x0, y0, w, h)
img_item.setRect(img_rect) 
for x in range(100):
    img_item.setImage(img_data[x,:,:])
    img_item.setRect(img_rect)


While this works, the behavior seems unexpected and undocumented. Should the current behavior be considered correct? If so it should be documented. If not where should we make the correction, I haven't dug into the ImageItem code to discover how hard a fix this would be. I am happy to explore with some guidance.

Thanks!
-Ed
Reply all
Reply to author
Forward
0 new messages