It's hard to draw conclusions without seeing more code.
I am still having difficulty to understand what exactly is not working for you.
Try out this code. Does that work for you?
#include <QApplication>
#include <QtGui>
int main(int argc, char* argv[])
{
// Image Label
imageLabel
->setBackgroundRole
(QPalette::Base);
imageLabel->setScaledContents(true);
// Loading Image
QObject::tr("Images (*.jpg *.png *.gif *.xpm)"));
imageLabel->setPixmap(fileName);
// CentralWidget
// Layout
lo->addWidget(imageLabel);
cw->setLayout(lo);
// Instantiating and showing mainwindow
mw.setCentralWidget(cw);
mw.show();
return app.exec();
}
#include <QApplication>
#include <QtGui>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
// Image Label
QLabel* imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
// Loading Image
QString fileName = QFileDialog::getOpenFileName(0,
QObject::tr("Open image"),
QApplication::applicationDirPath(),
QObject::tr("Images (*.jpg *.png *.gif *.xpm)"));
imageLabel->setPixmap(fileName);
// CentralWidget
QWidget* cw = new QWidget;
// Layout
QHBoxLayout* lo = new QHBoxLayout;
lo->addWidget(imageLabel);
cw->setLayout(lo);
// Instantiating and showing mainwindow
QMainWindow mw;
mw.setCentralWidget(cw);
mw.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks