Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Cannot display a picture in a QLabel

    General and Desktop
    3
    4
    905
    Loading More Posts
    • 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
      silep last edited by

      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 Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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 Reply Quote 0
        • S
          silep last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • First post
              Last post