0

I'm building a program where a user can interact with a pyqtgraph ImageView (e.g. place markers, change brightness and contrast). I want to be able to cycle through different images, but have each image remember its state with the markers etc. I feel like the most appropriate solution would be to create a copy of the ImageView for each image and show the current one and hide the other ones. What would be the best way to do that and would that even be a good idea?

My naive approach was placing an empty widget in Qt Designer (called graphWidget), promoting that to the ImageView class, and then in the program:

graphWidget_backup = self.graphWidget
secondWidget = pg.ImageView()
secondWidget.setImage(np.random.rand(256,256))

self.graphWidget = secondWidget

But with that, nothing happens.

Of course I could also just save the image data and all other changes manually and set them on the ImageView, but that feels less elegant and "object oriented".

2
  • Overwriting an instance attribute is useless for this: it's just a reference, it doesn't make the widget magically appear in place of another. A possible solution would be to use QStackedWidget (or QTabWidget) with all promoted widgets in Designer, and finally set the images by code. That is, unless you want to add the graph widgets dynamically. Feb 7 at 18:59
  • @musicamante Indeed I want to add the widgets dynamically.
    – LimaKilo
    Feb 8 at 10:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy