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. [Solved] Cannot display a picture in a QLabel

[Solved] Cannot display a picture in a QLabel

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.1k 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.
  • S Offline
    S Offline
    silep
    wrote on last edited by
    #1

    Hello,

    I am trying to open a simple Qlabel dialog box and to display a picture in it, but it doesn't open. The picture is located in my Debug.The lines are:
    @QLabel *label = new QLabel();
    label->setPixmap(QPixmap("apple.png"));@

    Would anyone have an idea about this problem?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You are not assigning any parent to the label

      You are not placing the label anywhere on screen, nor showing it with show()

      Please make absolutely sure that the PNG file is there (check with QFileInfo::exists())

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        silep
        wrote on last edited by
        #3

        Thanks for your reply! I just didn't showed the label, as you said. I thought that it worked like a QMessageBox. Now it works, my final code is:

        @QString fichier = QFileDialog::getOpenFileName(this,"Ouvrir un fichier",QString(),"Images (*.png *.gif *.jpg *.jpeg)");
        QLabel *label = new QLabel(cadre);
        label->setPixmap(QPixmap(fichier));
        label->move(300,300);
        label->show();@

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          QMessageBox is a special case like QFileDialog where the calls to exec()/show() are done for you when you use the static functions.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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