Reputation: 303
I am actually trying to develop a Graphical User Interface(GUI) using Qt 5.5 which goal is to load and open Tiff images (16.1 MB).
I had successfully loaded and displayed TIFF images using this code:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
QLabel *label = new QLabel(&fenetre);
QPixmap pixmap("D:/IS5337_2_010_00092.tif");
label->setPixmap(pixmap);
label->resize(pixmap.size());
window.show();
return app.exec();
}
However, when I tried to add a scrollarea using this code:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
QLabel *label = new QLabel(&fenetre);
QPixmap pixmap("D:/IS5337_2_010_00092.tif");
label->setPixmap(pixmap);
label->resize(pixmap.size());
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Light);
scrollArea->setWidget(label);
window.show();
return app.exec();
}
it did not work at all... The GUI did not show the TIFF image... only an empty grey window.
Could you help me please ?
Upvotes: 0
Views: 313
Reputation: 8698
The scrollArea object you use supposed to be connected with some parent widget:
// in that case we have window object of QWidget type that is running as
// main window for the app and that has label for embedding the pixmap in it
QScrollArea *scrollArea = new QScrollArea(&window); // set window as parent for scroll
scrollArea->setBackgroundRole(QPalette::Light);
QLabel *label = new QLabel; // (scrollArea) either set scroll as parent for label
// put the image in label, etc.
scrollArea->setWidget(label); // or set is as widget for scroll
// put the image in label, etc.
Upvotes: 1