Question

All my images are saved into a directory

pictures = '/x.com/user37/Public/....../images/'

I'm trying to load images from that directory onto my GUI screen. This is what I have in my __init__ method.

self.movieimg = QImage()
self.imagelbl = QLabel()
self.imagelbl.setAlignment(Qt.AlignCenter)
self.imagelbl.setPixmap(QPixmap.fromImage(self.movieimg))

When I include, after initializing a QGridLayout

layout.addWidget(self.movieimg, 1, 1)  

I get an error saying that argument 1 in addWidget is an invalid type. Why is this the case?

I created a dictionary entry = { } and I have another function where I call requests

def nextEntry(self)
    r= requests.get(self.MOVIES_URL + str(mid))
    resp = json.loads(r.content)
    img = resp['movie_id']

    self.movieimg = QImage(self.movie['img'])
    self.imglbl.setPixmap(QPixmap.fromImage(self.movieimg))

Thoughts? Do I need to directly call this function before that statement in the main __init__ function? Thank you!

Was it helpful?

Solution

self.movieimg is QImage() type and you need to pass QWidget type as first argument to addWidget method. QLabel() inherits from QWidget, so try to passing self.imagelbl instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top