PDA

View Full Version : Qlabel e jpeg



eltecprogetti
1st March 2012, 11:10
Hello,

is it possible to generate a qlabel and to see into the label an image jpeg?

Please, write two lines in qt4 very simple, so I can copy and paste in my application to look an image jpg on my form.

I am not able to do it!!!

If I design the form with the proprierty "pixmap" and select the file jpeg, I see the file on my qlabel, but when I start the program, the image is not present on the qlabel.

Help me, plese.

wysota
1st March 2012, 11:55
int main(int argc, char **argv) {
QApplication app(argc, argv);
QLabel *label = new QLabel;
label->setPixmap(QPixmap("/usr/share/icons/default.kde4/128x128/actions/voicecall.png"));
label->show();
app.exec();
delete label;
return 0;
}

eltecprogetti
1st March 2012, 14:01
Thanks for the answer.

I'm working on Windows, and the file jpg is on the root.




#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QLabel>
#include <QPixmap>

int main(int argc, char **argv)
{
QApplication app(argc, argv);
QLabel *label = new QLabel;
label->setPixmap(QPixmap("c:\presentation.jpg"));
label->show();
app.exec();
delete label;
return 0;
}



When I start the program, it appear a empty window with no label and no image......

And now?

wysota
1st March 2012, 20:36
You know that you should escape backslashes in strings, right?

Urthas
2nd March 2012, 02:26
Note that,
If you always use "/", Qt will translate your paths to conform to the underlying operating system. (from the documentation for QDir::separator() (https://qt-project.org/doc/qt-4.8/qdir.html#separator))