Important: Please read the Qt Code of Conduct -

PNG Image not showing in QLabel

  • Hi guys,

    So I have an issue with a QLabel and a png image.

    When using Qt Creators form, I can get my resource png image to show properly.

    However, when I try to do the same programatically, it doesn't show. This is what I have:

        QPointer<QLabel> label_qt_logo = new QLabel(mapWidget.value("widget_top"));
        QSizePolicy policy1(QSizePolicy::Fixed, QSizePolicy::Fixed);
        label_qt_logo->setMinimumSize(QSize(50, 50));
        label_qt_logo->setMaximumSize(QSize(100, 100));
        mapLabel.insert(label_qt_logo->objectName(), label_qt_logo);

    This is identical to the one Creator produced bar the QPointer bit and the mapLabel bit.

    Now, creator is aware of the logo as it shows up in the resource editor but when I launch the app it doesn't actually show.

    What gives?

    Cheers guys!

  • Hi Jamie welcome to the Qt Forum,

    Did you add the label to the layout of your form?

    If you use Qt Designer to design your form, Qt will generate a file with the code how it's build up (named something like ui_dialog.h) . You can look in there to learn and detect the missing pieces. So you have the best from both worlds.

  • Yes I have, I even tested the label by placing a "H" in it and it showed up.

  • Do you use a resource file?
    maybe your program couldn't find your image.

  • Yes, it would seem this must be the case but Qt Creator knows it exists because it even has the icon to show the image (if that makes sense).

  • did you have a look in the ui_dialog.h file as suggested above?

  • Yes, I have copied the code pretty much exactly, the only thing I changed was adding the insertion of an object into my hash map

  • Hi Jamie,

    Could you put the relevant parts in a minimal compilable example?

    otherwise we only can guess...