2

I'm trying to display a PNG image in a Widget using QLabel. I built the Widget using Qt Designer and the label shows the image properly. When I load the .ui into mi .py and execute it, everything shows up well, except for the label. I tried loading the QPixmap manually on the python code, but it didn't work either.

from PyQt5.QtWidgets import (QApplication, QLabel)
from PyQt5.QtGui import (QPixmap)
from PyQt5 import uic
import sys
import os

form = uic.loadUiType('gui/Files/Login.ui')


class LoginWindow(form[0], form[1]):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.logoLabel.setPixmap(QPixmap(os.path.abspath(os.path.join(os.path.dirname(__file__), 'logo.png'))))
        self.logoLabel.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = LoginWindow()
    win.show()
    app.exec_()

Any idea what am I doing wrong? Any sugestions on how could I display the image other than with QLabel?

Felipe Q.
  • 33
  • 1
  • 5
  • Are you sure that the path of the image is correct ?, I recommend you print the path, also it is not necessary to use the following instruction: `self.logoLabel.show()` – eyllanesc Nov 09 '17 at 02:43
  • The loading of image files (for `QIcon`, `QPixMap`, etc.) is done by plug-ins (e.g. qjpeg.dll for JPEG). May be, the resp. plug-in is missing. Though I think png support should be built-in in Qt. I found [Qt Image Formats](http://doc.qt.io/qt-5/qtimageformats-index.html) concerning this. – Scheff's Cat Nov 09 '17 at 09:11
  • A weird bug we one day faced was that we could load a thingy.jpg _with_ transparency. This annoyed me much because I was _sure_ that JPEG doesn't support transparency. Finally, it turned out that the thingy.jpg was actually a mis-named PNG file whereby the loader obviously trusted the magic code (inside the file) more than the wrong suffix and, thus, confused as... – Scheff's Cat Nov 09 '17 at 09:15

0 Answers0