[Solved] Cannot display a picture in a QLabel
-
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?
-
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())
-
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();@ -
Hi,
QMessageBox is a special case like QFileDialog where the calls to exec()/show() are done for you when you use the static functions.