0

Trying to get an image to display, but it just shows a blank screen, the path to the image is also correct because when I hover over the directory, it shows a preview of the image.

import sys

from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import (
    QLabel,
    QVBoxLayout,
    QMainWindow, QApplication, QStackedWidget,
)


class LoadingScreen(QMainWindow):
    def __init__(self):
        super().__init__()
        self.image_lbl = QLabel()
        self.load_image()
        lay = QVBoxLayout(self)
        lay.addWidget(self.image_lbl)

    def load_image(self):
        pixmap = QPixmap("../images/Loading.gif")
        self.image_lbl.setPixmap(QPixmap(pixmap))


if __name__ == '__main__':
    # main()
    app = QApplication(sys.argv)
    window = LoadingScreen()
    widget = QStackedWidget()
    widget.addWidget(window)
    widget.setFixedSize(450, 480)
    widget.show()
    app.exec_()
  • "the path to the image is also correct because when I hover over the directory, it shows a preview of the image." That only means that the file exists and it's an image. It only depends on the path in which the script is run and from which it's run. On un unrelated note, where did you see the approach of adding a QMainWindow to a QStackedWidget? I've seen this in the past, and its suggestion is rather odd (in my opinion, a very bad suggestion), and I'd like to understand where it comes from, as it seems some sort of tutorial/howto. – musicamante May 02 '21 at 16:06
  • i got part of my solution from this solution: https://stackoverflow.com/questions/59163389/how-do-i-open-an-image-in-a-separate-window-using-a-button-click-in-pyqt5 – Yellow Melon May 02 '21 at 16:13
  • I was referring to the QStackedWidget part. QMainWindow is intended as a *top level window*, while it's possible to make it a child of another widget, there are rare cases for which it makes sense, as most of the times it really doesn't. For instance, in your case. – musicamante May 02 '21 at 16:51

0 Answers0