Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PNG Image not showing in QLabel
QtWS25 Last Chance

PNG Image not showing in QLabel

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt 5.8qt creatorqlabelpngresources
8 Posts 2 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jamie_Edwards
    wrote on 6 Jun 2017, 18:06 last edited by
    #1

    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!

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eddy
      wrote on 6 Jun 2017, 19:12 last edited by
      #2

      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.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      2
      • J Offline
        J Offline
        Jamie_Edwards
        wrote on 8 Jun 2017, 13:58 last edited by
        #3

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

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Eddy
          wrote on 8 Jun 2017, 14:14 last edited by
          #4

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

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jamie_Edwards
            wrote on 8 Jun 2017, 14:26 last edited by
            #5

            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).

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Eddy
              wrote on 8 Jun 2017, 14:29 last edited by
              #6

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

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jamie_Edwards
                wrote on 12 Jun 2017, 14:07 last edited by
                #7

                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

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  Eddy
                  wrote on 12 Jun 2017, 14:56 last edited by
                  #8

                  Hi Jamie,

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

                  otherwise we only can guess...

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0

                  1/8

                  6 Jun 2017, 18:06

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved