2015-09-21 36 views
0

我实际上正在尝试开发一个使用Qt 5.5的图形用户界面(GUI),其目标是加载和打开Tiff图像(16.1 MB)。QScrollArea - 标签中没有显示TIFF图像

我已成功加载并显示使用此代码的TIFF图像:

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(); 
} 

然而,当我试图添加使用此代码scrollarea:

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(); 
} 

它并没有在所有的工作。 GUI没有显示TIFF图像...只有一个空的灰色窗口。

请问您能帮我吗?

回答

1

的scrollArea反对你使用应该与一些亲代部件连接:

// 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. 
+0

它的工作原理!非常感谢亚历山大。 –

+0

接受和upvote? – AlexanderVX

+0

是的,它完美的作品! –