PNG Image not showing in QLabel
-
wrote on 6 Jun 2017, 18:06 last edited by
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")); label_qt_logo->setObjectName(QStringLiteral("label_qt_logo")); QSizePolicy policy1(QSizePolicy::Fixed, QSizePolicy::Fixed); policy1.setHorizontalStretch(0); policy1.setVerticalStretch(0); policy1.setHeightForWidth(label_qt_logo->sizePolicy().hasHeightForWidth()); label_qt_logo->setSizePolicy(policy1); label_qt_logo->setMinimumSize(QSize(50, 50)); label_qt_logo->setMaximumSize(QSize(100, 100)); label_qt_logo->setPixmap(QPixmap(QString::fromUtf8(":/logos/qt_logo.png"))); label_qt_logo->setScaledContents(true); 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!
-
wrote on 6 Jun 2017, 19:12 last edited by
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.
-
wrote on 8 Jun 2017, 13:58 last edited by
Yes I have, I even tested the label by placing a "H" in it and it showed up.
-
wrote on 8 Jun 2017, 14:14 last edited by
Do you use a resource file?
maybe your program couldn't find your image. -
wrote on 8 Jun 2017, 14:26 last edited by
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).
-
wrote on 8 Jun 2017, 14:29 last edited by
did you have a look in the ui_dialog.h file as suggested above?
-
wrote on 12 Jun 2017, 14:07 last edited by
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
-
wrote on 12 Jun 2017, 14:56 last edited by
Hi Jamie,
Could you put the relevant parts in a minimal compilable example?
otherwise we only can guess...
1/8